Association agggregation and composition

9,614 views 19 slides Nov 22, 2012
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19

About This Presentation

No description available for this slideshow.


Slide Content

Disclaimer:This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra -Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Association aggregation and composition Jithin Mathew [email protected] www.facebook.com/jithinmatthew

They are the relationships among classes in java Association Aggregation Composition

Association It is a relationship between two objects. In other words, association defines the multiplicity between objects. You may be aware of one-to-one, one-to-many, many-to-one, many-to-many all these words define an association between objects. Aggregation is a special form of association. Composition is a special form of aggregation.

Association represents a general binary relationship that describes an activity between two classes

Another example for Association 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 It is a special case of association. A directional association between objects. When an object ‘has-a’ another object, then you have got an aggregation between them. Direction between them specified which object contains the other object. It is also called ‘Has-a’ relationship.

Note: If you delete the parent object, even then the child object may exist. One object can contain the other, but there is no restriction that the composed object has to exist in order to have existence of child object.

Examples for aggregation Take an example of Departments and developers. A developer can be only in one department like dotnet , java etc. but if we delete the Department object, still the Developer object exists. This is a “Has- a” relation. Let’s take another example of Department and teacher. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy.

Composition It is a special case of aggregation. In a more specific manner, a restricted aggregation is called composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition.

Example for composition A class contains students. A student cannot exist without a class. There exists composition between class and students.

Difference between aggregation and composition Composition is more restrictive. When there is a composition between two objects, the composed object cannot exist without the other object. This restriction is not there in aggregation. Though one object can contain the other object, there is no condition that the composed object must exist.

The existence of the composed object is entirely optional. In both aggregation and composition, direction is must. The direction specifies, which object contains the other object.

Example: A Library contains students and books. Relationship between library and student is aggregation . Relationship between library and book is composition . A student can exist without a library and therefore it is aggregation. A book cannot exist without a library and therefore its a composition.

Another Example The relation between a car and a tyre is an aggregation because the tyre is still a tyre if it is not attached to a car. The tyre has a life of its own. It exists outside of a car and you can use it on another car. The relation between a car and a carburetor is a composition because the carburetor has no use if it is out of a car.

Video link: You can refer more about this topic https://www.youtube.com/watch?v=0po_wmSEW1Q

Thank you
Tags