Beruflich Dokumente
Kultur Dokumente
Design of associations
Design of associations
Analyzing Association Traversal:
To change our decision of implementation
strategy with minimum effort, we should hide
the implementation, using access operations
to traverse and update the association.
Design of associations
One-way Associations:
When an association is traversed in only one
direction, then it is implemented as a
pointer, i.e., an attribute that contains an
object reference.
If the multiplicity is one as shown in Figure ,
then it is simple pointer; otherwise it is a set of
pointers.
Fig : 10.9
Design of associations
Two-way Associations:
Mostly, associations are traversed in both
directions, although not usually with equal
frequency.
There are three approaches for
implementation:
i)In bi-directional associations, if one direction
association is rarely used, then we should
implement this as unidirectional association.
Searching can perform the reverse association.
This way, we can reduce the storage and update
cost.
Two-way Associations:
Implementing as attributes in both
directions
Figure 10.10
This approach gives faster access but
also requires the updation of other
attributes in case of any change ,
otherwise the link will become
inconsistent.
Two-way Associations
Implementing as a distinct association
object, i.e., independent of either class as
shown in Figure 10.11
The association object may be
implemented using two objects: one in
forward direction, and the other in the
reverse direction.
This increases efficiency when hashing is
used, instead of attribute pointer.
Implementation of association as an
object(fig 10.11)
Link attributes
If an association has link attributes, then its
implementation depends on the multiplicity.
If association is one-to-one , the link attributes
can be stored as attributes of either object.
If association is many-to-one , the link attributes
can be stored as attributes of many object ,
since each many object appears only once in
the association.
If association is many-to-many , the link
attributes cannot be associated with either
object.