I've practiced that several times. You also see it quite a bit with Carbon and somewhat with OpenGL. (with texture objects, display lists, etc., but the "object" you store is actually an int that tells it which one to use) It can certainly be very useful.

Indeed, this is a great way to code. I'll admit I've been primarily using Objective-C nowadays, but I still like this approach a lot. It's too bad the article didn't get into subclassing... I would have liked to see if his approach was similar to mine.

Yep, I've always been fond of using OO designs even when the implementation language is C. I think you can very easily implement information hiding and seperation of interface vs implementation in C.

As for inheritance, while I do use it often, I find it to be the most abused aspect of OO languages and I don't miss having an "easy" form of it if I'm in a non OO language.

A long time ago I worked with a woman who had an entire C macro system that completely implemented v-tables w/inheritance etc behind the scenes. It was pretty slick, but it was overkill and reduced the maintainability of the code... to each their own.

Leisure Suit Lurie Wrote:I can't imagine "faking" inheritance in C, but you guys are the gurus...

It isn't even faked, IMHO. The old Mac Toolbox (pre-Carbon) does it with GrafPtr/WindowPeek/DialogPeek. It is a clear case of subclassing. Replacing methods as well as inheriting them or calling the method of the superclass are nicely done with some ProcPtrs (like in SAT and TransSkel) Mac Toolbox doesn't do that most of the time though. The only drawback is that it gets somewhat clumsy to access fields in inherited classes (which is why Mac Toolbox had both WindowPtrs and WindowPeek).

The big win with doing OO this way is compatibility. Your code can easily be mixed with any other language, since it has standard C interfaces everywhere, and methods are C-style procedure pointers. Everything can cope with that. Built-in OOP extensions are generally incompatible with the rest of the world. (Standards are good, so everybody wants their own, you know.)