T
Timie Milie
I have a tree of pure virtual classes with no data members or code
implementation (interfaces):
A
/ \
B C
/|\ /|\
/ | X | \
/ |/ \| \
D F G H
/ \
I J
(You'll need a fixed width font to view the ASCII art)
I also have an implementation class hierachy that mirrors the above
structure, i.e A --> AImpl, B--> BImpl and so on. Each implementation
class uses inheritance to add implementation functionality to its
parent class. Now I know the purpose of inheritance is code reuse, but
in this case it is very useful as each class merely extends
functionality and makes use of existing parent class functionality.
I tried using composition but it didn't scale well as I had to
implement every interface in the branch in each implementation classes
header - which were getting very large near the bottom of the tree.
Writing the implementation class also took ages as I had to wrap every
composited implementation function in an implementation class
function. I guess I could cut down on this using private inheritance
and the 'using' keyword? Multiple inheritance in the implementation
structure allowed me to keep my headers and source files smaller.
I am also having to use lots of virtual inheritance to share single
base classes.
As if that wasn't bad enough objects of class B can own a single
objects of class C (parent child relationships) via a (boost) shared
pointer. My copy constructor and assignment operators perform *deep*
copies.
I also use the virtual constructor idiom.
I also use the visitor pattern on the interface side. The latter
introduced nasty circular dependencies when just using implementation
classes that was fixed by using interfaces. Phew.
So here are my questions:
1. Is this actually going to end up being impossible to make work?
2. Is this really bad as opposed to generally ill advised?
3. Are there any easy to manage alternatives / have I misunderstood
composition or private inheritance?
4. What are the gotchas I have to watch out for if I continue down my
current path?
Thanks in advance,
TM
implementation (interfaces):
A
/ \
B C
/|\ /|\
/ | X | \
/ |/ \| \
D F G H
/ \
I J
(You'll need a fixed width font to view the ASCII art)
I also have an implementation class hierachy that mirrors the above
structure, i.e A --> AImpl, B--> BImpl and so on. Each implementation
class uses inheritance to add implementation functionality to its
parent class. Now I know the purpose of inheritance is code reuse, but
in this case it is very useful as each class merely extends
functionality and makes use of existing parent class functionality.
I tried using composition but it didn't scale well as I had to
implement every interface in the branch in each implementation classes
header - which were getting very large near the bottom of the tree.
Writing the implementation class also took ages as I had to wrap every
composited implementation function in an implementation class
function. I guess I could cut down on this using private inheritance
and the 'using' keyword? Multiple inheritance in the implementation
structure allowed me to keep my headers and source files smaller.
I am also having to use lots of virtual inheritance to share single
base classes.
As if that wasn't bad enough objects of class B can own a single
objects of class C (parent child relationships) via a (boost) shared
pointer. My copy constructor and assignment operators perform *deep*
copies.
I also use the virtual constructor idiom.
I also use the visitor pattern on the interface side. The latter
introduced nasty circular dependencies when just using implementation
classes that was fixed by using interfaces. Phew.
So here are my questions:
1. Is this actually going to end up being impossible to make work?
2. Is this really bad as opposed to generally ill advised?
3. Are there any easy to manage alternatives / have I misunderstood
composition or private inheritance?
4. What are the gotchas I have to watch out for if I continue down my
current path?
Thanks in advance,
TM