Menu ▼



Posted By :
avatarKrishna Narra
Total Views : 4404

Inheritance, Association, Aggregation, Composition


All the above defines the relationship between the objects and explains how objects are connected to each other’s and how they will behave.

Inheritance:

One class can use features from another class to extend its functionality. Inheritance based on IS-A Relationship. Inheritance is uni-directional. Inheritance is indicated by a solid line with a arrowhead pointing at the super class.  

Example: 1. House is a Building. But Building is not a House. 2. A Car is a Automobile. 3. A Cat is a Animal.


Here Animal class is the super class / Base class for the Cat & Dog Classes, which are derived classes.

Association:

Association represents a relationship between two or more objects where all objects have their own life cycle and there is no owner. Association is based on HAS-A Relationship.

This is represented by a solid line.



We take an example of relationship between Teacher and Student. Many students can have one teacher and one student can have many teachers. But there is no ownership between the objects and both have their own lifecycle. Both can be created and deleted independently.

Aggregation:

Aggregation is a special form of Association where all objects have their own life cycle but there is ownership. This represents whole-part or a-part-of relationship. Aggregation is based on HAS-A Relationship.

This is represented by a hollow diamond followed by a line.



We can take an example of relationship between Department and Teacher. A Teacher may belongs to many departments. Hence Teacher is a part of many departments. But if we delete a Department, Teacher Object will not destroy.

Composition:
Composition is a special form of Aggregation. In this relationship child objects does not have their life cycle without Parent object. If a parent object is deleted, all its child objects will also be deleted. Composition is based on PART-OF - death relationship. 
This is represented by a solid diamond followed by a line.



Here we can take another example of relationship between Building and Room. A Building can have many Rooms but a Room cannot belong to many Buildings. If we delete Building, Room will be automatically deleted.






comments powered by Disqus


Search dotnetlearners.com