CS3342 Lecture 5

UML - Sequence Diagram

  

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.)

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...

 

Main Message Types

Sequence Numbering 

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.

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. 

 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)

VS  

Caller is blocked                                     vs          Caller is not blocked

 

Object Creation Message

An object may create another object via an object creation message.
 

Object Destruction

Delete an object

 

 

Example:

Traffic Violations Lookup Screen

Summary:


 

 

 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

usetReceiver (r) when r is not null (r is not null as a condition).

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

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;  }
}

Example  - POS System:

Example  - Lookup Traffic Violation:

Reference (Ref) / InteractionUse

Fragment refers/points to another sequence diagram.

An InteractionUse refers to an Interaction scenario of objects
Example:
The sequence diagram below is the body of the operation “getBalance(accountNumber)”
 
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.

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

CombinedFragments - Break (break)

CombinedFragments - Iteration (loop)

 

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.

Implementation 1 vs Implementation 2

This structure above is appropriate when:

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

This structure above is appropriate when:

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

Example:

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值