A bidirectional association can be implemented by using pointers in both participating classes. For a single-valued mapping, there is a simple pointer from one object to the other. For a multivalued mapping, the object will have a set of pointers to the other objects. The accessor operations return the reference for a single-valued mapping or a copy of the set of references for a multivalued mapping to avoid breaking encapsulation.
Original Description:
buku ok
Original Title
Pages From EV616-Martin Fowler - Analysis Patterns_ Reusable Object Models-Addison-Wesley Professional (1996)(Encrypted)
A bidirectional association can be implemented by using pointers in both participating classes. For a single-valued mapping, there is a simple pointer from one object to the other. For a multivalued mapping, the object will have a set of pointers to the other objects. The accessor operations return the reference for a single-valued mapping or a copy of the set of references for a multivalued mapping to avoid breaking encapsulation.
A bidirectional association can be implemented by using pointers in both participating classes. For a single-valued mapping, there is a simple pointer from one object to the other. For a multivalued mapping, the object will have a set of pointers to the other objects. The accessor operations return the reference for a single-valued mapping or a copy of the set of references for a multivalued mapping to avoid breaking encapsulation.
Implementing a unidirectional association is pretty straightforward. You have a field in the class that is the source of the single mapping, and this field contains a reference to the target object. The accessor returns the reference and the modifier changes the reference.
14.1.5 Bidirectional Implementation by Pointers in
Both Directions In this implementation the association is implemented by pointers from both participating classes. If a mapping is single-valued, then there is a simple pointer from one object to another, such as the pointer from Peter to NASA shown in Figure 14.2. If a mapping is multivalued, then the object will have a set of pointers to the other objects (for example, in Figure 14.2 NASA points to a set of pointers that contains pointers to Peter, Jasper, and Paul). For languages that support containment, it may be useful to contain the set of pointers rather than to point to it. There may be space implications, however, since sets are able to grow at will. Similarly if a single-valued mapping points to a built-in data type or to another fundamental type, then containment can be used instead of a pointer.
Figure 14.2 Implementing by pointers in both directions.
The accessor operations are relatively straightforward. For a single-valued
mapping the accessor merely returns the reference. For a multivalued mapping the accessor returns a set of references; however, it must not return the set of references because the user of the set would then be able to change its membership and break the encapsulation. The encapsulation boundary should include all sets implementing multivalued mappings. One way out of this is to return a copy of the set so if any alterations are made, they do not
Pages From Copy of FX105-H. J. Harrington, Daryl Conner, Nicholas L. Horney, H. James Harrington, Darryl R. Conner - Project Change Management (1999, McGraw-Hill Companies) PDF