On my pet peeves of C++

Jun 12, 2006 17:20

See http://angelscat.livejournal.com/20172.html, in particular point 2.

Today I realize that I can put only an abstract base class and a "factory" function in the header file. The base class can contain whatever members that are to be publicly visible, and all function members except for the empty destructor can be purely virtual. The factory function simply dynamically allocates a concrete implementation and returns it as a pointer to the abstract base class.

Now this seems quite a bit simpler than ordinary pImpls--no need to manually redirect everything to the implementation class! Actually, only a little more code is needed than the C version. The overhead--a virtual method call--is not terribly annoying either. And, in the rare case that the implementation class is actually supposed to be inheritable, I can write another header solely for those who extend it.

Okay, I think I really need to read a design patterns book--even though it seems so boring for someone who has written soooo much C--if I'm to do any serious OO programming.

programming, c++

Previous post Next post
Up