Re: Polymorphism without virtual in C++
On Aug 7, 3:51 am, feel <feel...@gmail.com> wrote:
My code is a bad example ~_^. But if you can check with AcGe classes
in ObjectARX(from AutoDesk's AutoCAD sdk), you will see the same
design. The special case is:
1 for geometry class, esp for leaf classes, we donot want user to
extend it. if you want to add other kind of geometry type, please add
new class.The leaf of class tree is 'sealed' class.
2 Polymorphism in this design is the Impl pointer in root class. we
can implementation the real version class for every leaf class.
3 Except for leaf class, every class can not be initialize in the
stack.in my example code, you can not do this:
base1 b;
Why? because I donot want a big class in my header file. For geometry
classes,such as AcGeNurbCurve, there are many method we have to put
into interface. but we can split all these method into different
catalog: 3dentity, curve, spline curve. Then you will see a class
tree. There are small number methods in every node(classes in the
tree). And it's meaningfull for a geometry class library. we may do
something for all kind of curves,right? so if we use Pimpl idiom, you
can find Polymorphism.
This sounds more like letter-envelope than like compilation
firewall. But I'm not sure I've fully understood it. (The
letter-envelope idiom is used to make a class with value
semantics behave polymorphically.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34