Image Source on Google Search |
Q) Composition vs
Aggregation. How is Association related to them?
R)
R)
Association
-
it's a structural relationship between two classifiers - classes or use cases.
Cyclic association is also possible when the same entity plays two different
roles and contains an association describing the relationship between the two
roles.
In
UML notation an association is depicted by a solid line. For example: suppose
we have two entities Employee (EmpNo, Name, EmailId, Salary, DeptNo, Address)
and Department (DeptNo, DeptName). Now these two entities are having an
association. An association can have any cardinality at any of the two ends
depening on the particular relationship.
Aggregation
- this is
special type of association used for modelling 'Possession' (not Ownership)
with the restriction that it's NOT cyclic. That means, an entity can't have an aggregation
relationship with itself. This is the reason why an aggregation relationship
doesn't form a Graph, instead it forms a Tree.
Aggegation
is normally understood as a "has-a" relationship. Here both the
entities continue to have their own independent existence. In UML notation, an
aggregation is depicted by an unfilled diamond and a solid line. For example:
Consider two entities Employee (EmpNo, Name, EmailId, Salary, DeptNo, Address)
and Address (FlatNo, PlotNo, StreetName, Area, PinCode). As we might have
noticed that every Employee has an Address, but the lifetime of the an Address
instance is not governed by any Employee instance. It may continue to exist
even after the reclaimation of the Employee instance. Right?
Composition
- this is also a
special type of association used for modelling 'Ownership'. This is very
similar to Aggregation with the only difference that it depicts a Whole-part
relationship and the 'part' entity doesn't have its own independent existence.
The existence of entity depicting 'whole' giverns the lifetime of the 'part'
entity as well. For example: Consider two entities Employee (EmpNo, Name,
EmailId, Salary, DeptNo, Address) and EmailId (ID, domain). Now an independent
instance of EmailId entity doesn't really make sense unless it's associated
with an Employee instance.
Composition
is normally understood as a "contains-a" relations. Similar to
Aggregation, a Composition also forms a Tree only and not a Graph as it can't
be cyclic. In UML notation, a Compsoition is depicted by a filled diamond and a
solid line.
Aggregation vs
Composition
Aggregation
represents a "has-a" relationship whereas Composition represents a
"contains-a" OR "whole-part" relationship.
In
case of Aggregation, both the entities will continue to have their independent
existence whereas in case of Composition the lifetime of the entity
representing 'part' of the "whole-part" is governed by the entity
representing 'whole'.
Aggregation
represents a loose form of relationship as compared to that represented by
Composition which depicts a stronger relationship.
In
UML notation, an Aggregation relationship is depicted by an unfilled diamond
and a solid line whereas a Composition relationship is depicted by a filled
diamond and a solid line.
A
'part' of a Composition relationship can have only one 'whole' at a time i.e.,
a multiplicity of 1 whereas an Aggregation relationship can have any
multiplicity 0..* at the aggregate end.
Post a Comment
Post a Comment