C
craig
Given two existing but different classes OldA and OldB (that can not be
made to derive from any new base class); is there a way to make them
both "observer" objects so that they can be put in one central list and
updated thru a common interface. (i.e. observer->update( ..))?
Potential solution 1 (multiple inheritence): make a small new observer
class, and two new classes: NewA: derived from OldA, and Observer,..
and NewB: derived from OldB, and Observer. When walking thru a list of
NewA's and NewB's, cast the objects as Observer. (Can this even work?)
and call it's update function.
Potential solution 2 (composition): Make a new abstract composite class
"observer" and derive concrete observers ObserverA, and ObserverB that
contain "instances" of OldA, and OldB respectively. (The problem with
this approach in my case is that OldA is QtWidget and window management
becomes cumbersome.
Potential solution 3: Any other appraoches?
Any comments or rules-of-thumb greatly appreciated.
Thanks,
-Craig
made to derive from any new base class); is there a way to make them
both "observer" objects so that they can be put in one central list and
updated thru a common interface. (i.e. observer->update( ..))?
Potential solution 1 (multiple inheritence): make a small new observer
class, and two new classes: NewA: derived from OldA, and Observer,..
and NewB: derived from OldB, and Observer. When walking thru a list of
NewA's and NewB's, cast the objects as Observer. (Can this even work?)
and call it's update function.
Potential solution 2 (composition): Make a new abstract composite class
"observer" and derive concrete observers ObserverA, and ObserverB that
contain "instances" of OldA, and OldB respectively. (The problem with
this approach in my case is that OldA is QtWidget and window management
becomes cumbersome.
Potential solution 3: Any other appraoches?
Any comments or rules-of-thumb greatly appreciated.
Thanks,
-Craig