Has-a vs Is-a Relationships

Back to Composition over Inheritance

Is-a relationships are modeled through inheritance (a Dog is-a Animal), while has-a relationships are modeled through composition (a Car has-a Engine). Favoring has-a provides greater flexibility, as composed objects can be swapped at runtime and avoid tight coupling to parent class implementations.

programming-paradigms oop composition relationships