Lesson 4 | Modeling scenarios |
Objective | Map an Activity Diagram to a Sequence Diagram |
Modeling Sequences Scenarios
Scenarios and Sequences
A scenario describes an ordered series of events within a use case.
The goal of the sequence diagram is to assign responsibility for events to objects, thus defining the object interfaces.
To build a sequence diagram, you must match each scenario event to the objects that participate in the event as the sender and the receiver.
Tracing Interface Use Case
To draw the sequence diagram, evaluate each event in the scenario and identify the object that initiates the event. Then identify the object that is best suited to respond to the event. Draw an event arrow from the initiating object to the responding object. Label the event arrow with the event description from the scenario.
Mapping a scenario to a sequence diagram.
- Use one scenario as your source for the events and their order. Here we will use an activity diagram of the Choose Show use case to isolate one scenario. The red lines and activities identify one scenario (one logical path) in the activity diagram.
- For the first event, choose the class from the class diagram that describes the object initiating the event. The initiating object may be in a class that represents an actor, the system itself, or one of the problem domain resources. In this case the initiating object is a Customer.
- Draw the object at the top of the diagram.
- Draw a timeline vertically from the object downward.
- For each event, choose a class from the class diagram that describes the object best suited to receive and respond to the event.
- Draw the object at the top of the diagram.
- Draw a timeline vertically from the object downward.
- Draw a horizontal arrow from the sending object's timeline to the receiving object's timeline.
- Label the event line with the description of the event from the scenario.
- If the event requires a response, then add an event arrow from the receiving object's timeline back to the sending object's timeline.
- Label the return with the information that is returned. If the event simply returns control it is common to simply label the event return .
- Repeat this procedure for each event until all events in the scenario have been applied to the sequence diagram.
Drawing Sequence Diagram
As you place events on the sequence diagram, take care to position them on the timeline from top to bottom in the order that they occur. Quite often, once the events are placed on a timeline, you will notice inefficiencies that may be remedied simply by changing the order of the events. To change the order of events, move the events up or down the timeline.