Sunday, February 20, 2022

Inheritance, Association, Aggregation and Composition

Inheritance (IS-A) relationship:

Inheritance is  IS-A relationship, Let think we have a class Vehicle and a class called Car.

Car extends Vehicle class. This means Car IS-A vehicle.

Association (HAS-A) relationship:

There is a class Car and one more class called Engine.

Inside Car class we use Engine class. This relation will be called association(HAS-A) relationship.

Car HAS- A Engine.

Association is of two types:

1.    Aggregation:

Aggregation defines weak relationship in which both entity(class) can exist independently.

Let's say we have class Car and a entity Music System.

Car Has-A Music system but both can exist independently without any dependency on each other.

2. Composition:

Defines strong relationship, Car HAS-A Engine, both are dependent on each other. Individual existence has no importance.

        

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home