sequence diagrams csis3600. sequence diagrams a sequence diagram shows an interaction arranged in...

49
Sequence Diagrams CSIS3600

Upload: holly-gardner

Post on 05-Jan-2016

240 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Sequence Diagrams

CSIS3600

Page 2: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Sequence Diagrams

• A sequence diagram shows an interaction arranged in time sequence.

• In particular, it shows the objects participating in the interaction by their “lifelines”, and the messages that they exchange arranged in time sequence.

• It does not show the associations among the objects.  It represents an Interaction, which is a set of messages exchanged among objects within a collaboration to effect a desired operation or result.

Page 3: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Example Sequence Diagram

Page 4: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Sequence Diagram – Class Registration

Page 5: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Sequence Diagram and the Use Case

• Sequence diagrams are built from Use Cases. Each sequence diagram shows only the interactions pertinent to a specific use case.

• Use Cases did not identify separate objects. In a Sequence Diagram, we begin to relate the objects identified in the class diagram with the Use Case.

• Both the Class Diagrams and the Scenarios from the Use Case are used to build the Sequence Diagram.

Page 6: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Order Enter new customer

Enter new customer

Order Clerk

Order Clerk

Verify customer

Shipment

Customer

c ustomer Createorder order

Use Case Diagram Class Diagram

Sequence Diagram

Page 7: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

The Sequence Diagram

• A sequence diagram has two dimensions: – the vertical dimension represents time

– the horizontal dimension represents different objects and their interactions.

(although the dimensions may be reversed if desired).

• Normally time proceeds down the page.• Generally, there does not have to be significance

to the horizontal ordering of the objects, although logic and common sense should be applied.

Page 8: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Objects Lifelines Across Time

object 1 object 1

Lifelines

Page 9: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Object Interaction Arranged in a Time Sequence

object 1 object 1

Page 10: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Dimensions of the Sequence Diagram

horizontal dimension represents different objects

vertical dimension represents time

Page 11: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Sequence Diagram SyntaxAN ACTOR

AN OBJECT

A LIFELINE

A FOCUS OF CONTROL

A MESSAGE

OBJECT DESTRUCTION

anObject:aClass

aMessage()

x

Page 12: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Objects on the Sequence Diagram

• Sequence Diagrams represent a specific set of messages and interchanges between objects.

• Objects are represented instead of class.• Actors can also be represented.

• Objects might be depicted in 4 ways as outlined below:

Helen:customer :customer customer Customer

The class

Unidentified or anonymous customer object

Unidentified or anonymous customer object

A specific object whose identifier is Helen

Page 13: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Objects and Actors – The Same?

• Actors and objects are different even though they often have the same name.

• Actor is the external physical person who is playing a role.

• Object is the computer object that maintains information about the Actor.

• Obviously, we want to synchronize the internal object with the desires and actions of the external factor.

• In fact, the purpose of the system is to maintain internal computer information about the ordering activities of the external person.

Page 14: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Messages

• An OO system gets work done by a cooperative effort of individual objects that send messages to each other.

• The internal events identified by the flow of events within a scenario become the messages between objects (and objects and actors).

• A message is a communication between objects that conveys information with the expectation that action will ensue. The receipt of a message is a kind of event.

Page 15: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Description of the Sequence Diagram

A sequence diagram identifies the actors and classes (or instances of classes: objects) involved in the interaction, with a timeline (called a lifeline) for each. Between the lifelines, the sequence diagram shows the messages sent between the participants in the interaction.

object 1 object 1

Page 16: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Symbols of the Sequence Diagram

Page 17: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

External Actor(same as the Use Case)The external actor is graphically symbolized by a stickman figure. This illustrates a part of the environment that stimulates the system or is stimulated by it.

Page 18: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Object Symbol

An object is graphically symbolized as a rectangular box. This illustrates an object that is created, performs actions, and might be destroyed during the lifeline.

Page 19: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Lifeline

A lifeline is symbolized by a single broken line drawn vertically. This illustrates a representation of the existence of an object over a particular period of time.

Page 20: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Lifeline Node(sometimes shown, sometimes not)

A lifeline node is symbolized by a small circle. This is a connection point in a lifeline.

Page 21: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Activation

An activation is symbolized by a double broken line or a vertical rectangle. This illustrates the period during which an object is performing an action, either directly or through a subordinate procedure.

Page 22: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Activation as a vertical rectangle

Page 23: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

More on the Lifeline

• Lifelines show sequences. The messages higher up occur before those below.

• An object role is shown as a vertical dashed line called the “lifeline.”

• The lifeline represents the existence of the object at a particular time.

• If the object is created or destroyed during the period of time shown on the diagram, then its lifeline starts or stops at the appropriate point; otherwise it goes from the top to the bottom of the diagram.

• An object symbol is drawn at the head of the lifeline.

• Lifelines flow from TOP to BOTTOM.

object 1 object 1

message

message

message

message

message

message

Page 24: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Representations of the Lifeline • The lifeline represents the life of the

object throughout the period of active life.

• The lifeline is represented in two ways:

• Vertical dashed line is used when creation and destruction is not important for the scenario.

• When creation or destruction is important, a long narrow rectangle (or double dotted line) is used.

• The rectangle begins when an object comes into existence and ends on destruction.

• Often called the activation lifeline. The object is active during the period depicted by the rectangle.

object 1 object 1

message

message

message

message

message

message

Page 25: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Message Symbol

A message is shown as a horizontal solid arrow from the lifeline of one object to the lifeline of another object.

Page 26: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Notes on Messages

• In case of a message from an object to itself, the arrow may start and finish on the same object symbol.

• Messages preceded with an * indicate they can be sent multiple times.

• The type of arrow depicts the type of message.

• The arrow is labeled with the name of the message and its argument values.

• The arrow may also be labeled with a sequence number to show the sequence of the message in the overall interaction.  Sequence numbers are useful on the diagrams for identifying concurrent threads of control.

message to self

*may be sent multiple times

# [guard condition] return-value := message-name (parameter-list)

Page 27: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Flow of Control Message (simple message)• A flow of control message

is graphically symbolized as a line with a standard directional arrowhead.

• This illustrates a message that passes the focus of control from one object to another.

• Usually asynchronous but can be used when it is not known if the message is synchronous or asynchronous

• Most commonly used

Page 28: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Synchronous Message

• A synchronous message is graphically symbolized as a line with a solid directional arrowhead.

• Synchronous message is one where the caller has to wait for the receiving object to complete executing the called operation before it itself can resume execution.

Page 29: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Asynchronous Message

• An asynchronous message is graphically symbolized as a thick line with a directional half arrowhead.

• An asynchronous message is one where the sender does not have to wait for the recipient to handle the message. The sender can continue executing immediately after sending the message. Common when several objects operate in parallel and in real-time systems.

Page 30: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Return Message

• Represents explicit return of control from the object to which the message was sent

Page 31: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Send Message(not explored in this class)• A send message is

graphically symbolized by a "boat-shaped" object.

• This connects into object lifelines and acts as the source of any type of message.

Page 32: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Branching of Messages

Page 33: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Naming the Messages

• Initially, messages are expressed in free format text. (Message is simply named.)

• Ultimately (and potentially only in the design model instances of the sequence diagram), the messages are rigorously specified in terms of message numbers, optional precursor conditions (termed guards), a message name and optional parameters. In this form, the message names correspond to invocations of correspondingly named operations of the recipient class.

Page 34: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Message Label

A message symbol has 2 parts: direction arrow and the descriptor

The fully qualified descriptor is:

[guard condition] return-value := message-name (parameter-list)

– [guard condition] is a true/false condition that is a test to see whether the message can be sent.

– message-name descriptor to identify the action

– (parameter-list) are the parameters to be passed

– return-value is an extended message descriptor syntax is used when you want to indicate that the message is invoking a method. The extended syntax includes a possible return value from the method and the list of input variables needed by the method.

Message label descriptor

Page 35: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Example: message-name formats Message name only:

RingTelephone

Message name indicating parameters will be passedItemInquiry()

Message name including parametersCreateOrderItem (ItemId,qty)

Guard condition with message name including parameters[existsPrereqs=”true”] checkPrereqs (prereqs)

Guard condition, return value and message name with parameter[FirstItem] OrderNumber := CreateOrder()(this can be confusing so instead of placing the return value in the message label, an additional arrow is often added on the diagram depicting the return message.)

Page 36: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Object Deletion

• An object deletion is graphically symbolized by an X

• Indicates the deletion of an object.

Page 37: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Sequence Diagram for a Class Registration Scenario with Prerequisites

Page 38: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Suggestions for Sequence Diagram Development

1. Identify all objects and actors that are involved in the scenario. Use only actors from the use case diagram and objects from classes in the class diagram. (If new actors or objects are needed, add them and then update your other diagrams.)

Order Enter new customer

Enter new customer

Order Clerk

Order Clerk

Verify customer

Shipment

Customer

c ustomer Createorder order

Use Case Diagram Class Diagram

Sequence Diagram

Page 39: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Step 2

2. Based on the flow of activities, identify each message that will be required to carry out the scenario.

a. Identify both the source object or actor for the message and the destination object or actor.

i. For the source of a message identify objects that need the service

ii. Identify object that has access to the required input parameters.iii. If there is a one-to-many relationship, then frequently the

object on the ‘one’ side creates the message and sends it to the object on the ‘many’ side.

Page 40: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Step 3

3. Next determine whether each message is always sent or whether it is sent only under certain conditions.

Example: Checking for prerequisites only if course is open

[CheckIfOpen=“true”]existsPreReqs()

Page 41: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Step 44. Sequence the messages correctly and attach them to the

appropriate lifelines of the actors and objects.

Page 42: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Step 5

5. Add the formal syntax to the messages (conditions, message names and passed parameters).

Page 43: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Step 6

6. If needed, add the response message.

Page 44: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Notes on Sequence Diagrams

• Sequence diagrams begin interaction modeling

• This is where you begin to see how the new system will ‘behave’

• More more info: http://www.sdmagazine.com/print/documentID=11072

Page 45: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Sequence Diagram Objectives

• Sequence diagrams facilitate the discovery of things left out in the earlier static view of the system presented in the class diagram

• Sequence diagrams find new classes, new attributes and many of the behaviors (operations) that are needed– In fact some suggest that methods not be

assigned until now because there wasn’t enough information available

Page 46: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Concluding ThoughtsSequence Diagrams and Analysis

• At the analysis stage you are trying to make sure that you know what the user wants. No more, no less. In effect analysis is a more detailed form of requirements capture. At this stage you are more concerned with the overall structure of interactions between the objects than you are with any minute detail of precisely how each operation works. For this reason you should choose not to take things down to too detailed a level. We're trying to capture the most important decisions about how the objects are going to interact.

Page 47: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

• At the design stage you include everything. The only reason not to include detail at the design stage is as a trade-off: we don't need to model this detail because a) it's obvious b) there's enough there for our experienced programmers to know what I mean and c) I save time not including extraneous detail. Other than that you would expect to see everything in the design sequence diagram. Detail of how each significant operation works, error values, error handling, exceptions etc, etc.

• Sequence diagrams can easily become very complex - even at the analysis stage (but at the analysis stage this is usually overdone modeling). At the design stage they can become hugely complicated. We will not get to this level of detail in this course because we focus on analysis.

Concluding ThoughtsSequence Diagrams and Analysis

Page 48: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Top Mistakes in Creating Sequence Diagrams

• Not doing a sequence diagram for each use case• Not updating class diagrams as soon as attribute

and behavior discoveries are found• Turning the sequence diagram into a flow chart

instead of using it to identify behaviors among objects

• Not focusing on interesting methods (focusing on mundane)

• Not addressing flow of control in messages

Page 49: Sequence Diagrams CSIS3600. Sequence Diagrams A sequence diagram shows an interaction arranged in time sequence. In particular, it shows the objects participating

Once again the operative word is iterative.