JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Member-only story

Composition Over Inheritance: A Deep Dive into Flexible Object-Oriented Design

Vítor Azevedo
JavaScript in Plain English
5 min readNov 2, 2024

Understanding Composition and Inheritance

Composition: The “Has-a” Relationship

Composition involves building functionality by assembling small, modular components, each with distinct responsibilities. This allows developers to create objects by combining individual, self-contained parts, rather than relying on an inflexible class hierarchy. Composition embodies a “has-a” relationship — for example, a Car object may "have a" Engine component, without needing to be a subclass of Engine.

Inheritance: The “Is-a” Relationship

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Written by Vítor Azevedo

Frontend Developer with 25+ years' expertise in HTML, CSS, JavaScript, Angular and Vue. Builds dynamic, user-centric web apps. Award-winning projects.

No responses yet

Write a response

Recommended from Medium

Lists

See more recommendations