Friday, July 27, 2007

Modeling a sequence diagram

Uses a time-oriented visualization. Illustrate interactions between objects. Model objects and messages between objects. When one object wants to send a message to another object, the second object has to have a way to receive the message. The message must match an interface provided by the second object.

Modeling an object lifeline
The sequence diagram uses two fundamental notation elements
-object lifelines
-messages or stimulus

The object lifeline includes the rectangular object icon and the vertical dashed line below each object. The line is a timeline that runs from the beginning of a scenario at the top of the diagram, to the end of the scenario at the bottom of the diagram.

Modeling a message or stimulus
A message is a definition of some type of communication between objects. It may invoke an operation, raise a signal, or cause the creation or destruction of the target object. A stimulus is an instance of a message.
A message is modeled as an arrow. The type of arrow visually describes the type of message. Messages are placed horizontally between the object lifelines. The relative vertical position on the timelines represents the order in which the messages happen.


Figure 8-3: Messages are placed on the object lifelines to model object interactions. Relative vertical position indicates the order of execution from top to bottom.

If one message is placed on the timeline above a second message, then the first message is sent before the second message.

The tail of the message arrow identifies the sender. The head of the message arrow identifies the receiver.

The return arrow is drawn using a dashed line and a stick arrow to distingush it from the synchronous message arrow.

The syntax for a message is as follows:
predecessors '/' sequence-term iteration [condition] return ':=' operation
stimulus - is an item of communication between two objects. It associated with both a sending and a receiving object. It may invoke an operation, raise a signal, or even cause an object to be created or destroyed. It may include parameters/arguments. It is associated with the procedure that causes it to be sent.
message - stimulus is an instance of a message. Is the specification of a stimulus. Specification includes the roles that the sender object and the receiver object play in the interaction, and the procedure that dispatches the stimulus.
operation - explains the procedure that the message invokes on the receiving object.
signal - A message may raise a signal. It does not require a return from the receiving object.
exception - is a type of signal. Sending out a message containig an object that describes the error condition.

Synchronous Messages - A return is needed, so the sender waits for the return before proceeding with any other activity. Modeled using a solid line and a solid arrowhead
Self-reference message - The sender and the receiver for the message are the same object. The message arrow leaves and come back to the same timeline. The send and return connot be combined into one message.
Asynchronous message - that do not have a return. Modeled using a solid line and a stick arrowhead


Timed Message - express the timing parameters for the message. for ex. {if you don't get a respose from the event object within 2 seconds, bypass the request and send an error to the user interface}

Iteration - excecute one or more messages in a sequence more than once. An asterisk (*) indicates that the message will execute repeately. You can enclose a conditional statement in square braces([]).

Conditions - A condition is expressed as text enclosed within square braces[]. UML supports the ability to model branching on a descision. This involves drawing a diamond and multiple arrows from the same point on the timeline to multiple destinations.

Modeling activation/focus of control
Activation means that an object is occupied performing a task. Deactivation means that the object is idle, waiting for a message.
To show that an object is active, widen the vertical object lifeline to a narrow rectangle. An object becomes active at the top of the rectangle. An object is deactivated when it finishes its work. This is usually illustrated as a message arrow leaving the object lifeline.

Modeling object creating and destruction
If an object is at the top of the page, means that the object exists when the sequence starts.
If the object is created during the execution of the scenario, it should appear somewhere below the top of the diagram.
To show that an object is terminated, place an X at the point in the object lifeline when the termination occurs. The absence of the X on an object lifeline means that the object lives on after this sequence of events is ended.

No comments: