Unit 12 Flashcards
Consider the association from Hotel to RoomType in Figure 3. What do you know about objects linked by the association Hotel to RoomType?
The association from Hotel to RoomType expresses the fact that each Hotel object has to be able to hold the object identities of many RoomType objects. Other associations with multiplicity ‘many’ have been qualified, to indicate that for each value of a qualifier attribute there is at most one object at the other end; however, they are still associations between one object at one end and many at the other end.
What does Figure 3 tell us about the objects linked by the association ReserverPayer to Reservation?
The association from ReserverPayer to Reservation expresses the fact that each ReserverPayer object has to be able to hold the object identities of many Reservation objects, but for each ReserverPayer object and a reservation number there is at most one Reservation object.
Consider the qualified association between HotelChain and ReserverPayer in Figure 3.
What does this association tell us?
The association expresses the fact that ReserverPayer objects are identified in the system through their id (assigned to them the first time they register and used to represent their value identity. The HotelChain object is linked to all ReserverPayer objects via this association, and will perform a mapping between the value and object identities of ReserverPayer objects in order to be able to reference them.
How do you express this new navigability in Java?
The following instance variable declaration would need to be added to class Room.
Set roomReservations;
Because a Room needs to know about all Reservations, we have opted to use a Set rather than a Map. Had this been a qualified association whereby a specific reservation could be identified from its number, this would no longer be the case.
The Room constructor would be modified as follows. (see pic)