top | item 19619650

(no title)

Gladdyu | 6 years ago

One example is if suddenly you would require to inherit from the same object multiple times. Example - if you have a "team" object, you might at first inherit it from a list/set (as a team could be a list of members). However, later down the line, you might also want to model backups for your team. You can't inherit from list/set again, so what are you going to do? It it much cleaner in general to avoid inheritance as much as possible and only modelling the data as internal, not publicly-accessible state (by composing smaller state objects). Inheritance on the other hand (in most languages), can make your data model more visible from the outside.

This isn't to say there aren't valid use cases for inheritance (eg. runtime polymorphism), though if something can be accomplished through composition, it's usually the better approach as it only modifies inner details of an object, and not the external interface (of which the inherited classes are part).

discuss

order

No comments yet.