In my C++ project I often has the following situation, where I have a Class A
which has a pointer to the interface of another class X
. That class A
is extended to handle a subtype of X
. And this situation repeats again.
Note that at each layer the interface changes (new object methods are added, and some others are overloaded), so at each subclass of A
, the pointer to X
is cast to the the subclass of X
+----------+ +----------+
| | A has X | |
| A +-------------------> X |
+-----+----+ +-----+----+
| |
| |
| |
+-----+----+ +-----+----+
| | | |
| B +-------------------> Y |
+-----+----+ +-----+----+
| |
+-----+----+ +-----+----+
| | | |
| C +-------------------> Z |
+----------+ +----------+
I wonder if there is any pattern to deal with this situation, or is it intrinsically a bad design?
Aucun commentaire:
Enregistrer un commentaire