Suppose I have such requirement:
The objects in the system all derive from a base class named IObject, and it may have objects with color, objects with transformations, and both.
Now there are 2 approach to design the class hierarchy.
The first one is:
just let concrete class derived from IObject, and also select "capability" interfaces as its base class to indicate it support such behavior, like interface: IHasColor,
IHasTransformation
The second one is:
Organize the base classes, and let concrete classes derived from one of them: IObject, IColorObject, ITransfromationObject , IColorAndTransformationObject
I prefer the first one (Does it have a formal name? ) as it is more flexible, and as you can see the second one may have class combination explosion problem when there are many attributes like color, transformation...
I would like to know your ideas and suggestions.
Thanks.