221022 association, aggregation, composition에 대한 앎

늘숲·2022년 10월 22일
0









Difference between Association,Aggregation,Composition and Inheritance

Most of you are familar with these terms are being used when we design a object-oriented model diagram. These relationship not only represents static view of your application but also representing construction of executable code of software application.

It's adding more advantage of developing a software appliaction by designing the relationship between classes, their responsibility and implementation which helps to construct the executable code for forward and reverse engineering of any system.

Association:-
Association is a relationship between two objects. It's denoted by "has-a" relationship. In this relationship all objects have their own lifecycle and there is no owner. Let's take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently.

Aggregation:-
Aggregation is a another type of specialised form of Association where all objects have their own lifecycle, but there is ownership and child objects can not belong to another parent object. Let's take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department teacher object will not be destroyed. We can think about it as a "has-a" relationship.

Composition:-
Composition is again specialised form of Aggregation and we can call this as a "death" relationship. It is a strong type of Aggregation. Child object does not have its lifecycle and if parent object is deleted, all child objects will also be deleted. Let's take again an example of relationship between House and Rooms. House can contain multiple rooms – there is no independent life of room and any room can not belong to two different houses. If we delete the house – room will automatically be deleted. Let's take another example relationship between Questions and Options. Single questions can have multiple options and option can not belong to multiple questions. If we delete questions options will automatically be deleted. Let's take another example of relationship between Car and Moter, Moter is a vital part of Car, if you remove moter then Car become useless.

Hence, we can take lots of example of composition in real world that represent a strong relationship classes .

Inheritance :-
Inheritance is an another type of relationship and it's denoted by "is-a" relationship. Inheritance is the inclusion of behaviour (i.e. methods) and state (i.e. variables) of a base class in a derived. for example- Circle is a shape, Rectangle is a Shape.

reference : https://itexpertsconsultant.wordpress.com/2016/04/22/difference-between-associationaggregationcomposition-and-inheritance/

profile
발전, 그리고 숲

0개의 댓글