wiki:CompositionOverInheritance

Prefer Composition Over Inheritance

Languages like Go does not have the mechanism of inheritance, nevertheless they are object-oriented, given that objects are composed of several behaviors or traits.

Scala advocates for similar approach.

The crucial difference is that one composes traits instead of inheriting class-methods from superclasses. This makes hierarchies more flat and wide, which means more branches, which provides a better encapsulation (less sharing).

The metaphor is use (compose) only what is needed.

Last modified 2 years ago Last modified on Dec 19, 2017, 6:39:39 AM
Note: See TracWiki for help on using the wiki.