8/18/2021
75

Creating sequence diagram for every use case can be a waste of time and effort. Fairly technical. Use case diagram. Use case diagram depicts how actors (a person or a system) interacts with a solution to accomplish one or more of the person’s or systems goals. It visually depicts the scope of the solution, the actors involved, and the use cases. The interaction that takes place in a collaboration that either realizes a use case or an operation (instance diagrams or generic diagrams) high-level interactions between user of the system and the system, between the system and other systems, or between subsystems.

Your global IP address is: 207.46.13.33 40.77.189.238. Copyright © 2006-2021 myglobalip.com - All rights reserved. Global ip address lookup.

The sequence diagram represents the flow of messages in the system and is also termed as an event diagram. It helps in envisioning several dynamic scenarios. It portrays the communication between any two lifelines as a time-ordered sequence of events, such that these lifelines took part at the run time. In UML, the lifeline is represented by a vertical bar, whereas the message flow is represented by a vertical dotted line that extends across the bottom of the page. It incorporates the iterations as well as branching.

Purpose of a Sequence Diagram

  1. A use case diagram is used to represent the dynamic behavior of a system. It encapsulates the system's functionality by incorporating use cases, actors, and their relationships. It models the tasks, services, and functions required by a system/subsystem of an application.
  2. In the tree view, right-click the package or subsystem in which you want to include a use case diagram, then point to New, and then click Use Case Diagram. A blank page appears, and the UML Use Case stencil becomes the top-most stencil. An icon representing the diagram is added to the tree view.
  1. To model high-level interaction among active objects within a system.
  2. To model interaction among objects inside a collaboration realizing a use case.
  3. It either models generic interactions or some certain instances of interaction.

Notations of a Sequence Diagram

Lifeline

An individual participant in the sequence diagram is represented by a lifeline. It is positioned at the top of the diagram.

Actor

A role played by an entity that interacts with the subject is called as an actor. It is out of the scope of the system. It represents the role, which involves human users and external hardware or subjects. An actor may or may not represent a physical entity, but it purely depicts the role of an entity. Several distinct roles can be played by an actor or vice versa.

Activation

Use

It is represented by a thin rectangle on the lifeline. It describes that time period in which an operation is performed by an element, such that the top and the bottom of the rectangle is associated with the initiation and the completion time, each respectively.

Messages

The messages depict the interaction between the objects and are represented by arrows. They are in the sequential order on the lifeline. The core of the sequence diagram is formed by messages and lifelines.

Following are types of messages enlisted below:

  • Call Message: It defines a particular communication between the lifelines of an interaction, which represents that the target lifeline has invoked an operation.
  • Return Message: It defines a particular communication between the lifelines of interaction that represent the flow of information from the receiver of the corresponding caller message.
  • Self Message: It describes a communication, particularly between the lifelines of an interaction that represents a message of the same lifeline, has been invoked.
  • Recursive Message: A self message sent for recursive purpose is called a recursive message. In other words, it can be said that the recursive message is a special case of the self message as it represents the recursive calls.
  • Create Message: It describes a communication, particularly between the lifelines of an interaction describing that the target (lifeline) has been instantiated.
  • Destroy Message: It describes a communication, particularly between the lifelines of an interaction that depicts a request to destroy the lifecycle of the target.
  • Duration Message: It describes a communication particularly between the lifelines of an interaction, which portrays the time passage of the message while modeling a system.
Sequence

Note

A note is the capability of attaching several remarks to the element. It basically carries useful information for the modelers.

Sequence Fragments

Use Case Diagram Examples

  1. Sequence fragments have been introduced by UML 2.0, which makes it quite easy for the creation and maintenance of an accurate sequence diagram.
  2. It is represented by a box called a combined fragment, encloses a part of interaction inside a sequence diagram.
  3. The type of fragment is shown by a fragment operator.

Types of fragments

Following are the types of fragments enlisted below;

OperatorFragment Type
altAlternative multiple fragments: The only fragment for which the condition is true, will execute.
optOptional: If the supplied condition is true, only then the fragments will execute. It is similar to alt with only one trace.
parParallel: Parallel executes fragments.
loopLoop: Fragments are run multiple times, and the basis of interaction is shown by the guard.
regionCritical region: Only one thread can execute a fragment at once.
negNegative: A worthless communication is shown by the fragment.
refReference: An interaction portrayed in another diagram. In this, a frame is drawn so as to cover the lifelines involved in the communication. The parameter and return value can be explained.
sdSequence Diagram: It is used to surround the whole sequence diagram.

Use Case Activity Sequence Diagram

Example of a Sequence Diagram

An example of a high-level sequence diagram for online bookshop is given below.

Any online customer can search for a book catalog, view a description of a particular book, add a book to its shopping cart, and do checkout.

Benefits of a Sequence Diagram

  1. It explores the real-time application.
  2. It depicts the message flow between the different objects.
  3. It has easy maintenance.
  4. It is easy to generate.
  5. Implement both forward and reverse engineering.
  6. It can easily update as per the new change in the system.

The drawback of a Sequence Diagram

  1. In the case of too many lifelines, the sequence diagram can get more complex.
  2. The incorrect result may be produced, if the order of the flow of messages changes.
  3. Since each sequence needs distinct notations for its representation, it may make the diagram more complex.
  4. The type of sequence is decided by the type of message.
Next TopicUML Collaboration Diagram

Artifacts > Analysis & Design Artifact Set > Design Model.. > Design Model > Guidelines > Sequence Diagram

Guidelines: Sequence Diagram


Sequence Diagram

A sequence diagram describes a pattern of interaction among objects, arranged in a chronological order; it shows the objects participating in the interaction by their 'lifelines' and the messages that they send to each other.
Topics
  • Contents of Sequence Diagrams

In most cases, we use a sequence diagram to illustrate use-case realizations (see Artifact: Use-Case Realizations), i.e. to show how objects interact to perform the behavior of all or part of a use case. One or more sequence diagrams may illustrate the object interactions which enact a use case. A typical organization is to have one sequence diagram for the main flow of events and one sequence diagram for each independent sub-flow of the use case.

Sequence diagrams are particularly important to designers because they clarify the roles of objects in a flow and thus provide basic input for determining class responsibilities and interfaces.

Unlike a collaboration diagram, a sequence diagram includes chronological sequences, but does not include object relationships. Sequence diagrams and collaboration diagrams express similar information, but show it in different ways. Sequence diagrams show the explicit sequence of messages and are better when it is important to visualize the time ordering of messages. When you are interested in the structural relationships among the instances in an interaction, use a collaboration diagram. See Guidelines: Collaboration Diagram for more information.

Contents of Sequence Diagrams

You can have objects and actor instances in sequence diagrams, together with messages describing how they interact. The diagram describes what takes place in the participating objects, in terms of activations, and how the objects communicate by sending messages to one another. You can make a sequence diagram for each variant of a use case's flow of events.

A sequence diagram that describes part of the flow of events of the use case Place Local Call in a simple Phone Switch.

Objects

An object is shown as a vertical dashed line called the 'lifeline'. The lifeline represents the existence of the object at a particular time. An object symbol is drawn at the head of the lifeline, and shows the name of the object and its class underlined, and separated by a colon:

objectname : classname

You can use objects in sequence diagrams in the following ways:

  • A lifeline can represent an object or its class. Thus, you can use a lifeline to model both class and object behavior. Usually, however, a lifeline represents all the objects of a certain class.
  • An object's class can be unspecified. Normally you create a sequence diagram with objects first, and specify their classes later.
  • The objects can be unnamed, but you should name them if you want to discriminate different objects of the same class.
  • Several lifelines in the same diagram can represent different objects of the same class; but, as stated previously, the objects should be named that so you can discriminate between the two objects.
  • A lifeline that represents a class can exist in parallel with lifelines that represent objects of that class. The object name of the lifeline that represents the class can be set to the name of the class.

Normally an actor instance is represented by the first (left-most) lifeline in the sequence diagram, as the invoker of the interaction. If you have several actor instances in the same diagram, try keeping them either at the left-most, or the right-most lifelines.

A message is a communication between objects that conveys information with the expectation that activity will ensue; in sequence diagrams, a message is shown as a horizontal solid arrow from the lifeline of one object to the lifeline of another object. In the case of a message from an object to itself, the arrow may start and finish on the same lifeline. The arrow is labeled with the name of the message, and its parameters. The arrow may also be labeled with a sequence number to show the sequence of the message in the overall interaction. Sequence numbers are often omitted in sequence diagrams, in which the physical location of the arrow shows the relative sequence.

A message can be unassigned, meaning that its name is a temporary string that describes the overall meaning of the message and is not the name of an operation of the receiving object. You can later assign the message by specifying the operation of the message's destination object. The specified operation will then replace the name of the message.

Scripts describe the flow of events textually in a sequence diagram.

You should position the scripts to the left of the lifelines so that you can read the complete flow from top to bottom (see figure above). You can attach scripts to a certain message, thus ensuring that the script moves with the message.

Centralized control of a flow of events or part of the flow of events means that a few objects steer the flow by sending messages to, and receiving messages from other objects. These controlling objects decide the order in which other objects will be activated in the use case. Interaction among the rest of the objects is very minor or does not exist.

Example

In the Recycling-Machine System, the use case Print Daily Report keeps track of - among other things - the number and type of returned objects, and writes the tally on a receipt. The Report Generator control object decides the order in which the sums will be extracted and written.

The behavior structure of the use case Print Daily Report is centralized in the Report Generator control object.

This is an example of centralized behavior. The control structure is centralized primarily because the different sub-event phases of the flow of events are not dependent on each other. The main advantage of this approach is that each object does not have to keep track of the next object's tally. To change the order of the sub-event phases, you merely make the change in the control object. You can also easily add still another sub-event phase if, for example, a new type of return item is included. Another advantage to this structure is that you can easily reuse the various sub-event phases in other use cases because the order of behavior is not built into the objects.

Decentralizedcontrol arises when the participating objects communicate directly with one another, not through one or more controlling objects.

Example

In the use case Send Letter someone mails a letter to another country through a post office. The letter is first sent to the country of the addressee. In the country, the letter is sent to a specific city. The city, in turn, sends the letter to the home of the addressee.

The behavior structure of the use case Send Letter is decentralized.

The use case behavior is a decentralized flow of events. The sub-event phases belong together. The sender of the letter speaks of 'sending a letter to someone.' He neither needs nor wants to know the details of how letters are forwarded in countries or cities. (Probably, if someone were mailing a letter within the same country, not all these actions would occur.)

The type of control used depends on the application. In general, you should try to achieve independent objects, that is, to delegate various tasks to the objects most naturally suited to perform them.

A flow of events with centralized control will have a 'fork-shaped' sequence diagram. On the other hand, a 'stairway-shaped' sequence diagram illustrates that the control-structure is decentralized for the participating objects.

A centralized control structure in a flow of events produces a 'fork-shaped' sequence diagram. A decentralized control structure produces a 'stairway-shaped' sequence diagram.

The behavior structure of a use-case realization most often consists of a mix of centralized and decentralized behavior.

A decentralized structure is appropriate:

  • If the sub-event phases are tightly coupled. This will be the case if the participating objects:
    • Form a part-of or consists-of hierarchy, such as Country - State - City;
    • Form an information hierarchy, such as CEO - Division Manager - Section Manager;
    • Represent a fixed chronological progression (the sequence of sub-event phases will always be performed in the same order), such as Advertisement - Order - Invoice -Delivery - Payment; or
    • Form a conceptual inheritance hierarchy, such as Animal - Mammal - Cat.
  • If you want to encapsulate, and thereby make abstractions of, functionality. This is good for someone who always wants to use the whole functionality, because the functionality can become unnecessarily hard to grasp if the behavior structure is centralized.

A centralized structure is appropriate:

  • If the order in which the sub-event phases will be performed is likely to change.
  • If you expect to insert new sub-event phases.
  • If you want to keep parts of the functionality reusable as separate pieces.

Use Case Sequence Diagram Online

System

Simple Sequence Diagram

Rational Unified Process

Use Case Diagram Tutorial