CS3342 Lecture 5

UML - Sequence Diagram

CS3342 Lecture 5_第1张图片

  

Sequence Diagram

Shows: Objects or Actors (NOT classes or the system itself) as vertical dotted lines.
(events as horizontal arrows from the sender object to the receiver object.)

CS3342 Lecture 5_第2张图片

There is no limit on the number of actor objects or objects per sequence diagram

 

Sequence Diagram Basic Elements:

Frame: define the scope of a sequence diagram

Object, message, life-line, condition, execution occurrence...

CS3342 Lecture 5_第3张图片

 

Main Message Types

CS3342 Lecture 5_第4张图片

Sequence Numbering 

CS3342 Lecture 5_第5张图片in Visual Paradigm

Synchronous Messages  

Typically implemented as a function/method call
The method that handles the message is completed before the caller resumes execution.
Caller CANNOT do anything else until returned from callee.
CS3342 Lecture 5_第6张图片

Return Values 

This is Optional, using a dashed arrow with a label indicating the return value.
  May not need to model a return value when it is obvious what is being returned, e.g., getTotal( ),
  This avoids too many lines on the diagram
  Model a return value when you need to refer to a specific value that is not obvious. E.g., On the last slide, the line “yes, it is opened” can be omitted
 
Asynchronous Messages  
Caller do not need to wait for the message to be handled before it continues to execute. (allows multi-tasking)
Caller can do something else while waiting callee. 

CS3342 Lecture 5_第7张图片 Alibaba can talk to the Thief during the magic door is being opened.

 

Example: Direct Printing (Synchronous Messages and Call)  VS Background Printing (Asynchronous Messages and Call)

CS3342 Lecture 5_第8张图片VS  CS3342 Lecture 5_第9张图片

Caller is blocked                                     vs          Caller is not blocked

 CS3342 Lecture 5_第10张图片

Object Creation Message

An object may create another object via an object creation message.
  CS3342 Lecture 5_第11张图片

Object Destruction

Delete an object

 

CS3342 Lecture 5_第12张图片

 

Example:

Traffic Violations Lookup Screen

CS3342 Lecture 5_第13张图片

Summary:

CS3342 Lecture 5_第14张图片


 

CS3342 Lecture 5_第15张图片

 

 Condition 

A condition is an expression relating different attributes of an object and/or values.
Notation: 
Conditions are used as guards(if true) on transitions. A guarded transition fires when its event occurs and satisfies its condition

CS3342 Lecture 5_第16张图片usetReceiver (r) when r is not null (r is not null as a condition).

Lost Message ( to black hole!) & Found Message (from black hole!)

CS3342 Lecture 5_第17张图片

Lost messages are those that are either sent but not arrived, or which go to a recipient not shown on the current diagram. Connecting to other functions in another diagram.

Found messages are those that arrived from an unknown source, or from a sender not shown on the current diagram. They are denoted going to or coming from an endpoint element.

Example - Register an Account:

import java.util.*;

public class RegisterController {

  private List _accounts = new ArrayList();

    public void register(String name, int age) {

        Account account = new Account();

        account.setId(1);

        account.setName(name);

        account.setAge(age);

        _accounts.add(account);
    }

    public List getAccounts(){

        return _accounts;  }
}

CS3342 Lecture 5_第18张图片

Example  - POS System:

CS3342 Lecture 5_第19张图片

Example  - Lookup Traffic Violation:

CS3342 Lecture 5_第20张图片

Reference (Ref) / InteractionUse

Fragment refers/points to another sequence diagram.

An InteractionUse refers to an Interaction scenario of objects
Example:
CS3342 Lecture 5_第21张图片
The sequence diagram below is the body of the operation “getBalance(accountNumber)”
CS3342 Lecture 5_第22张图片
 
CombinedFragments
CombinedFragments are used to describe control logics in a sequence diagram.

They are only for modeling simple combinations of scenarios.

  • Alternatives (alt)
  • Option (opt)
  • Iteration (loop)
  • Break (breaks, jumps out of a loop)
  • ..etc (There are more) 

CombinedFragments - Alternatives (alt) if... else...

Represents a choice of behavior.

Similar to the “switch statements” or if-statement.

The chosen operand must have an explicit conditional expression evaluates to true.

CS3342 Lecture 5_第23张图片

CombinedFragments - Option (opt)

Designates that the CombinedFragment represents a choice of behavior where either the (sole) operand happens or nothing happens.
In short, an option is the same as an alternative CombinedFragment where there is one operand with non-empty content and the second operand is empty.
i.e. If (Condition), do_something, there is no else

CS3342 Lecture 5_第24张图片

CombinedFragments - Break (break)

CS3342 Lecture 5_第25张图片

CombinedFragments - Iteration (loop)

CS3342 Lecture 5_第26张图片

CS3342 Lecture 5_第27张图片

 

CASE STUDY (Structure of sequence diagram):

Scenario: The application deals with a warehouse with automatic forklift trucks that move pallets.

A technician gives an order specifying only where a pallet is to be moved to.

All loads are placed on pallets that can be moved around automatically in the warehouse.

Since the pallets are moved automatically, the loads must be checked every tenth move at a checking station to make sure that the loads are still stable on the pallets.

We must therefore keep track of how many times a pallet has been moved.

CS3342 Lecture 5_第28张图片

CS3342 Lecture 5_第29张图片

Implementation 1 vs Implementation 2

CS3342 Lecture 5_第30张图片

This structure above is appropriate when:

  • the operations can change order
  • new operations could be inserted

CS3342 Lecture 5_第31张图片

This structure above is appropriate when:

  • nthe operations have a strong connection
  • nthe operations will always be performed in the same order

Example:

CS3342 Lecture 5_第32张图片

Structure of Sequence Diagrams

strong connection exists among the operations if the objects:
  • form a “consists-of” hierarchy, such as country-state-city
  • form an information hierarchy, such as document-chapter-section-paragraph-character
  • represent a fixed procedural sequence such as advertisement-order-invoice-delivery-payment
  • form a (conceptual) inheritance hierarchy, such as animal-mammal-cat

 

CAN reverse Java code to sequence diagram in VP

CS3342 Lecture 5_第33张图片

CS3342 Lecture 5_第34张图片

CS3342 Lecture 5_第35张图片

CS3342 Lecture 5_第36张图片

Summary:

  • In OO Design, we may use sequence diagram is to specify our object interactions.
    • We use such diagrams to illustrate how objects invoke the methods of the other objects in the same diagram 
  • In dynamic modeling, we need to make decisions on whether to use centralized control or decentralized/distributed control.
  • To sketch sequence diagrams, we use both basic elements, InteractionUse, and the CombinedFragments
  • Sequence diagram helps software designers to communicate effectively with different stakeholders, such as programmers, customers, end-users on the object interactions and behaviors. 

转载于:https://www.cnblogs.com/charon922/p/8622862.html

你可能感兴趣的:(java,sketch)