Composition

Composition means building a class by giving it other objects as fields to which it delegates work, a "has a" relationship. It is more flexible than inheritance because it lets you change the parts without breaking a hierarchy: "prefer composition over inheritance".

Example

class Voiture {
    private final Moteur moteur = new Moteur();
}

Related concepts

The whole glossary