77

ISBN : 978-81-963532-2-3 (E-Book) Fig : Representation of composition Association vs. Aggregation vs. Composition • Association is the most general (m:n) relationship. Aggregation is a stronger relationship where one is a part of the other. Composition is even stronger than aggregation, ties the lifecycle of the part and the whole together. • Association relationship can be reflexive (objects can have relation to itself), but aggregation cannot be reflexive. Moreover, aggregation is anti-symmetric (If B is a part of A, A cannot be a part of B). • Composition has the property of exclusive aggregation i.e. an object can be a part of only one composite at a time. For example, a Frame belongs to exactly one Window,whereas in simple aggregation, a part may be shared by several objects. For example, a Wall may be a part of one or more Room objects. •  in general, the lifetime of parts and composite coincides  parts with non-fixed multiplicity may be created after composite itself  parts might be explicitly removed before the death of the composite For example, when a Frame is created, it has to be attached to an enclosing Window. Similarly, when the Window is destroyed, it must in turn destroy its Frame parts. Inheritance vs. Aggregation/Composition • Inheritance describes ‘is a’ / ‘is a kind of’ relationship between classes (base class - derived class) whereas aggregation describes ‘has a’ relationship between classes. Inheritance means that the object of the derived class inherits the properties of the base class; aggregation means that the object of the whole has objects of the part. For example, the relation “cash payment is a kind of payment” is modeled using inheritance; “purchase 72 Software Engineering Keerthana P, Manasa KN, Ganga D Bengal In addition, in composition, the whole has the responsibility for the disposition of all its parts, i.e. for their creation and destruction.

78 Publizr Home


You need flash player to view this online publication