0

I am learning OOP from scratch. I have some confusion about Inheritance and Aggregation. After researching on the net I am more confused that is Inheritance opposite of Aggregation ? Is it true ?

zakilive
  • 1
  • 5
  • 3
    That's a little like saying that "green" is the opposite of "three". They serve two different purposes. – Ignacio Vazquez-Abrams Sep 01 '17 at 15:31
  • Maybe you're thinking about [*aggregation* versus *composition*](https://softwareengineering.stackexchange.com/questions/61376/aggregation-vs-composition)? – lurker Sep 01 '17 at 15:33
  • The word "opposite" is not well-defined when used with respect to software development patterns. Inheritance and aggregation are two different tools to solve the same problem (roughly *"how can I extend the functionality of a class"*). A comparison can be found here: https://stackoverflow.com/q/269496/87698. I am voting to close this as a duplicate, feel free to edit and clarify your question if you disagree. – Heinzi Sep 01 '17 at 15:37
  • Possible duplicate of [Inheritance vs. Aggregation](https://stackoverflow.com/questions/269496/inheritance-vs-aggregation) – Heinzi Sep 01 '17 at 15:37

1 Answers1

0

Inheritance is a specialised form of Aggregation. For example

Handsfree is aggregated in cell phone. (Aggregation)
Motherboard is composed of ICs. (Composition)
A policeman is a human. (Inheritance)

These are types of association from weak to strong

Association->Aggregation->Composition->Inheritance.

Amsal N
  • 201
  • 2
  • 10