Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects...

27
Sequence and Sequence and Collaboration Collaboration Diagram Diagram
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    228
  • download

    1

Transcript of Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects...

Page 1: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Sequence and Sequence and Collaboration Collaboration

DiagramDiagram

Page 2: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Interaction DiagramInteraction Diagram

models describe how groups of models describe how groups of objectsobjects collaborate in some behavior collaborate in some behavior

NOTE THAT: not classNOTE THAT: not class typically, captures the behavior of a typically, captures the behavior of a

single use casesingle use case Two kindsTwo kinds

sequence diagramssequence diagrams collaboration diagramscollaboration diagrams

Page 3: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

an OrderEntry window

an Order an OrderLine

a Stock Item

a Reorderitem

a DeliveryItem

prepare()*prepare() hasStock:=

check()

[hasStock]remove()

needsReorder:=needsToReorder()

[needsReorder]newreturn

[hasStock]new

Creation

return

condition

self call

iteration

messageobject

deletion

Page 4: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

When to use sequence When to use sequence diagramdiagram

One of the hardest things to understand in One of the hardest things to understand in an object-oriented program is the overall an object-oriented program is the overall flow of control.flow of control.

A good design has lots of small methods in A good design has lots of small methods in different classes and at times it can be different classes and at times it can be tricky to figure out the overall sequence of tricky to figure out the overall sequence of behaviorbehavior

Sequence diagram helps you see the Sequence diagram helps you see the sequencesequence

valuable for concurrent processvaluable for concurrent process

Page 5: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

a Transaction

a Transactioncoordinator

a firstTransaction

checker

a second Transaction

Checker

new

new

new

new

OK

OK

alldone

alldone

be Valid

Concurrent processes and activation

asynchronousmessage

otherprocessingsuppressed

Page 6: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Sequence diagramSequence diagram

請看一下下面兩張請看一下下面兩張 sequence diagramsequence diagram

Page 7: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.
Page 8: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.
Page 9: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

CommentsComments

Sequence diagram Sequence diagram 並不擅長展示有 並不擅長展示有 looloop p 等的演算法等的演算法

適合展示某個複雜的互動情境適合展示某個複雜的互動情境

Page 10: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

建立與刪除物件建立與刪除物件

Page 11: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

CommentsComments

Sequence diagram Sequence diagram 並不擅長展示有 並不擅長展示有 looloop p 等的演算法等的演算法

適合展示某個複雜的互動情境適合展示某個複雜的互動情境

Loops, Conditionals, and the LikeA common issue with sequence diagrams is how to show looping and conditional behavior. The first thing to point out is that this isn't what sequence diagrams are good at. If you want to show control structures like this, you are better off with an activity diagram or indeed with code itself. Treat sequence diagrams as a visualization of how objects interact rather than as a way of modeling control logic.

Page 12: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.
Page 13: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

procedure dispatchforeach (lineitem)if (product.value > $10K)careful.dispatchelseregular.dispatchend ifend forif (needsConfirmation) messenger.confirm

end procedure

Page 14: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Loop and alternative Loop and alternative frameframe

Loop Loop 以及 以及 alternative alternative 框架是 框架是 UML 2.UML 2.0 0 之後才之後才

有的有的 有些人不喜歡 有些人不喜歡 loop loop 以及 以及 alternative alternative 框框架,而自行採用其他的方法如下圖架,而自行採用其他的方法如下圖

Page 15: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.
Page 16: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Frame optionFrame option alt Alternative multiple fragments; only the one whose conditi

on is true will execute (Figure 4.4). opt Optional; the fragment executes only if the supplied condi

tion is true. Equivalent to an alt with only one trace (Figure 4.4).

par Parallel; each fragment is run in parallel. loop Loop; the fragment may execute multiple times, and the

guard indicates the basis of iteration (Figure 4.4). region Critical region; the fragment can have only one thread

executing it at once. neg Negative; the fragment shows an invalid interaction. ref Reference; refers to an interaction defined on another diag

ram. The frame is drawn to cover the lifelines involved in the interaction. You can define parameters and a return value.

sd Sequence diagram; used to surround an entire sequence diagram, if you wish.

Page 17: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Collaboration DiagramCollaboration Diagram

The sequence is indicated by The sequence is indicated by numbering the messagenumbering the message

the spatial layout allows you to show the spatial layout allows you to show other things more easilyother things more easily

show how object link togethershow how object link together you can overlay packages or other you can overlay packages or other

information more easilyinformation more easily

Page 18: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

:Order Entry Window

:Order

Macallan Line: Order Line

:Delivery Item

Macallan Stock:StockItem

:Reorder Item

1:prepare()

2: *[for all order lines]: prepare()

3:has Stock:=check()4:[has Stock]:remove()

5:needsReorder :=needToReorder()

6:[needsReoder]:new

7:[hasStock]:new

object

message

sequence number

selfdelegation

Page 19: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Sequence or Sequence or Collaboration?Collaboration?

different people have different different people have different preferencepreferencefor different situationfor different situation

interaction diagrams can awkward interaction diagrams can awkward to use when exploring alternativesto use when exploring alternatives

Page 20: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

How to find methods How to find methods (behaviors, operations) of (behaviors, operations) of

objectobject 好,你應該知道要怎麼樣以好,你應該知道要怎麼樣以 sequence diasequence dia

gramgram 描述物件之間的互動描述物件之間的互動 重點是,你的物件的 重點是,你的物件的 method method 根本還沒根本還沒有個譜?有個譜?

你怎麼找他們?你怎麼找他們?

Page 21: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

9.2. The KRB Seven-Step 9.2. The KRB Seven-Step Method. Method.

Step Step Operations (i.e., Operations (i.e., Behavior) Behavior)

1. By Inspection1. By Inspection2. Basic 2. Basic CRUDCRUD3. Use Cases3. Use Cases4. Statechart Diagram4. Statechart Diagram5. CRC Cards5. CRC Cards6. 6. CRUDCRUD Revisited Revisited

Six techniques for Six techniques for Finding OperationsFinding Operations

Page 22: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

What is a use caseWhat is a use case ?? 使用案例 (系統使用情境 使用案例 (系統使用情境 scenarioscenario )) Use cases Use cases 是你的系統所要完成的功能是你的系統所要完成的功能 這些功能當然要由你所設計的 這些功能當然要由你所設計的 objects objects 互互動來完成動來完成

請看上次的規格書請看上次的規格書

Page 23: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.
Page 24: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

What is a scenario (What is a scenario ( 情境)情境)A scenario is a sequence of steps describing an int

eraction between a userand a system. So if we have a Web-based on-line store, we might

have a Buy a Product scenario that would say this:

The customer browses the catalog and adds desired items to the shopping basket. When the customer wishes to pay, the customer describes the shipping and credit card information and confirms the sale. The system checks the authorization on the credit card and confirms the sale both immediately and with a follow-up e-mail.

Page 25: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

What is a use case?What is a use case?

一個使用案例是一組(系統使用,或系統一個使用案例是一組(系統使用,或系統操作)情境來達成某個目標操作)情境來達成某個目標

一個趨勢是規格書的寫法漸漸由 一個趨勢是規格書的寫法漸漸由 use caseuse cases s 所取代,尤其是軟體代工產業所取代,尤其是軟體代工產業

Page 26: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

Use Case diagramUse Case diagram

Page 27: Sequence and Collaboration Diagram. Interaction Diagram models describe how groups of objects collaborate in some behavior models describe how groups.

use caseuse case 干尋找物件干尋找物件 methodmethod啥事啥事

一旦有了 一旦有了 use case (use case ( 可以有正式文件,或可以有正式文件,或者是 建模者自行寫下一些者是 建模者自行寫下一些 scenarioscenario

Scenarios (use cases) Scenarios (use cases) 是系統行為的起頭是系統行為的起頭 每一個每一個 use case use case 最終一定要由系統中的物最終一定要由系統中的物件來完成件來完成

OKOK , 接著?, 接著?