This is probably a silly question, but I'm becoming suspicious I'm not realizing some better design.
On a few cases, I have classes designed with a rich interface being used as aggregatees on other classes:
CInventory has a well delineated interface. Functions to equip and unequip items, drop and pick them, and much more.Code:class CBeing { /* ... */ private: CInventory inv_; };
The above example forces me to expose CInventory interface by adding to CBeing interface function members that basically all they do is call inv_ own methods. Only a very small subset of CInventory interface will not be exposed through CBeing. Note this is meant to be an aggregation. inv_ will be destroyed when CBeing is destroyed.
It's not that it shocks me. However, it makes me suspicious that I'm failing to realize some other better choice than carrying over to the aggregator an aggregatee's interface.
Is there?



LinkBack URL
About LinkBacks



Second, if is-a doesn't apply but you think inheritance could simplify your life, chances are good that your owning class' interface could be improved so that instead of just wrapping calls to the owned class' interface, you design an interface that still uses the owned class without duplicating its design. That usually results in more fluid interfaces across the board. It takes a great deal more effort though.