How do we know to favour composition over generalisation is always the right choice?
- by Carnotaurus
Whether an object physically exists or not, we can choose to model it in different ways. We could arbitarily use generalisation or composition in many cases. However, the GoF principle of "favour composition over generalisation [sic]" guides us to use composition. So, when we model, for example, a line then we create a class that contains two members PointA and PointB of the type Point (composition) instead of extending Point (generalisation). This is just a simplified example of how we can arbitarily choose composition or inheritance to model, despite that objects are usually much more complex.
How do we know that this is the right choice? It matters at least because there could be a ton of refactoring to do if it is wrong?