Composition over inheritance

In object-oriented programming, composition over inheritance (sometimes composition with forwarding or composite reuse) is a common design pattern that tries to achieve code reuse without requiring inheritance. Instead of having two child classes inherit functionality from a common parent, composition simulates inheritance by having the children include a copy of a "pseudo-parent" class as a field, which implements the functionality common to the two classes.

Source: Wikipedia — Composition over inheritance (CC BY-SA 4.0)

Composition over inheritance

In object-oriented programming, composition over inheritance (sometimes composition with forwarding or composite reuse) is a common design pattern that tries to achieve code reuse without requiring inheritance. Instead of having two child classes inherit functionality from a common parent, composition simulates inheritance by having the children include a copy of a "pseudo-parent" class as a field, which implements the functionality common to the two classes.

Source: Wikipedia "Composition over inheritance" · CC BY-SA 4.0

Share this article: X · Bluesky
Privacy Policy