[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: object-oriented C programming

On Tue, 5 Dec 2000, Sam Couter wrote:

> OO design doesn't require an OO language. An OO language makes it easier,
> and can enforce OO to varying degrees, but the main ingredient is
> discipline.

No argument here, but why _wouldn't_ one use an OO language for such
designs?  That's what they're there for!

> Data encapsulation and providing methods to manipulate that data makes a
> design OO, even if it doesn't have inheritence (which you can fake in C
> with a "isa" member on your structs, but it's messy) or polymorphism.

I would argue this.  I always preferred Stroustrup's separation of "data
abstraction," "object-oriented programming" and "generic programming."  I
think it's a very important distinction.

> And even though C++ provides language support for data encapsulation and
> hiding, inheritance and polymorphism, I wouldn't submit it as a good example
> of an OO language. 

Maybe not, but it is a practical one, IMHO.

> It provides all the same shortcomings of C (it's just a superset of C to
> begin with, poor start), 

I've heard this often, but I submit that without the C compatability, C++
would have failed.  And it cleans up C enough to be at least passable.

> it makes private members well-known (and hence not-so-private), etc. I
> won't go any further, better people than I have already done so. ;)

Note that one can avoid this by using abstract base classes,
implementation classes and multiple inheritence.  Or one can use
composition to keep a pointer to the implementation object, etc.
There are many, many techniques to decouple things.  Does the language
allow the programming to shoot himself in the foot.  You bet.  But
I'd rather have that and the zero-overhead rule than something that
forces me to use somebody's idea of the "right" design.



"Some little people have music in them, but Fats, he was all music,
 and you know how big he was."  --  James P. Johnson

Reply to: