0% found this document useful (0 votes)
34 views2 pages

Inheritance (IS-A) vs. Composition (HAS-A) Relationship: Description

inheritance is most significant process in oop .detailed overview and understanding of oop is available along with practice exercises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Inheritance (IS-A) vs. Composition (HAS-A) Relationship: Description

inheritance is most significant process in oop .detailed overview and understanding of oop is available along with practice exercises
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Inheritance (IS-A) vs.

Composition (HAS-A)
Relationship
Description
One of the advantages of Object-Oriented programming language is code reuse.
There are two ways we can do code reuse either by implementation of
inheritance (IS-A relationship), or object composition (HAS-A relationship).

IS-A Relationship:
In object oriented programming, the concept of IS-A is a totally based on
Inheritance, which can be of two types Class Inheritance or Interface Inheritance.
It is just like saying "A is a B type of thing". For example, Apple is a Fruit, Car is a
Vehicle etc. Inheritance is uni-directional. For example House is a Building. But
Building is not a House.

HAS-A Relationship:
Has-A means an instance of one class has a reference to an instance of
another class or another instance of same class. It is also known as
composition or aggregation.
e.g. XLi has Engine, or House has Bathroom. Lets understand these concepts
with example of Car class.

Aggregation:
Without existence of container object, if there is a chance of existence of
contained objects then container and contained objects are said to be loosely
associated and this strong association is known as aggregation.
e.g: A department has several professors. Without existence of
departments there is good chance for the professors to exist. Hence
professors and department are loosely associated and this loose association
is known as Aggregation.

Composition:
Without existence of container object, if there is no chance of existence of
contained objects then container and contained objects are said to be strongly
associated and this strong association is known as composition.
e.g: A university has several departments. Without existence of university
there is no chance for the departments to exist. Hence university and
departments are strongly associated and this strong association is known as
composition.

While aggregation is a has a relationship, composition is a consists of


relationship.

You might also like