Re: Sibling Polymorphism
greg.door@gmail.com (Greg D) wrote (abridged):
IMHO, this stinks to high-heaven, but I thought I'd see what the
community experience is--- maybe there's a good reason for this that
I've just never considered.
I've not come across anything quite like it. I have used:
Derived *Base::getDerived();
on its own as a form of down-cast, mainly for convenience and efficiency
(in my experience, a virtual function call is a lot faster than a
dynamic_cast<>).
I have also used pairs of objects where A has a get_b() and B has a
get_a(). This was for an intentionally rigid lattice of object types
where each item had pointers to its neighbours. The types were tightly
coupled because the design was using the type system to enforce
constraints on the lattice structure. However, I didn't have anything
like your C that inherited from both A and B.
I don't know that I'd call it an anti-pattern. If A and B are alternate,
orthogonal views of an object, then it might make sense for either view
to provide optional access to the other one, and for a class to implement
both.
Can you say more about your example? What were the actual names of A, B
and C?
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]