06
-
1.0 Object Diagrams
- Object Diagrams are very useful for helping to develop class diagrams as you can use the objects and their interactions to identify classes/associations. That is, one can use specific scenarios to develop class diagrams. Whereas class diagrams are used to document the structure of the classes, object diagrams are an instantiation of all (or part) of the class diagram. That is, a specific instance of the class with a set of appropriate attribute values. This is very useful when try to uncover the details of a class by using actual objects (instances).
- In summary:
- An Object Diagram is an instance of a Class Diagram.
- It shows a snapshot of the detailed state of a system at a point in time – that is, a specific scenario
- Where you have a class in the class diagram replace it with a particular object(s) from the scenario.
- If there are more than one instance (object) of the class in the scenario, then each must be drawn e.g. if there are 3 rooms mentioned in a scenario for the class diagram you draw 3 rectangles, one for each instance/object. As in the class diagram you use lines to indicate associations. Because all instances/objects are included in the diagram each link is a one-to-one association, so no multiplicity numbers are shown.
-
6.1 Scenarios
- Example
- A Customer can make a number of Reservations for Room(s) in different types of Properties ( e.g Hotels/B&Bs etc)
- Suppose we had the class “Room” in the class diagram, and an instance of it – called ‘Harbour’ in the scenario. Thus, there is a room called ‘Harbour’. We could draw Harbour in the object diagram in any of the following ways shown below:
- More scenarios:
- 1 ) Fred Carts (Customer Object) phones to make a reservation at the “Bay View B&B” (Property Object) for three nights. The agent offers 3 rooms. The rooms are named: “Beach”, “Sea View” & “Harbour”. (Room Objects). Fred makes an actual reservation (Reservation Object) for the “Beach” room.
- 2 ) Joan Smith (Customer Object) phones the booking agent and asks to book 7 rooms for a company event. The receptionist checks the system and finds that there are 7 rooms available in the “Executive Retreat” Hotel. (Property Object).
- The rooms are (Room Objects) :
- Doubles: 203, 204, 303, 304
- Single: 208, 308, 309
- Joan agrees that all seven rooms should be booked and the agent makes the reservation (Reservation Object).
- Scenario 2
- 3 ) Helen Roy (Customer Object) phones to make a reservation at the “Golf View” Hotel (Property Object). She would like to have 3 rooms. The “pink”, “blue“ & “violet” rooms (Room Objects) are available. The agent makes the reservation (Reservation Object)
- Examine each Object diagram with the Class Diagram. Are there any corrections or improvements that you might make to the original (example) class diagram?
- Based on the Object Diagram Solutions – it is clear that there IS an Error in the Original Class Diagram. The relationship between Reservation and Room is incorrect – it should be:
- Updated Class Diagram:
-
6.2 Object Diagrams : Summary
- It shows a snapshot of the detailed state of a system
- Can use the Objects and their interactions to identify classes/associations
- each link is a one-to-one association
- so no multiplicity numbers are shown.
- Very useful for :
- Helping to develop class diagrams
- Checking class diagrams