DEV Community

Said Olano
Said Olano

Posted on

Composition Over Inheritance Principle

  • Less coupling between classes. Using inheritance, subclasses easily make assumptions, and break LSP.
  • Test for LSP (substitutability) to decide when to inherit.
  • Compose when there is a "has a" (or "uses a") relationship, inherit when "is a".

Top comments (0)