You are on page 1of 49

UML (Unified Modeling Language) 簡介

2010-07-27
OLD_RD2 李宗沂
Agenda

• Introduction
• Structure Diagram
• Behavior Diagram
• Tools
• Discuss
Introduction

• History
• Three Amigos and OMG
• Usage of UML
• Meta Modeling
• Diagrams Overview (UML 2.0)
History

UML 2.3 2010-05


Three Amigos and OMG

• Three Amigos
– Grady Booch
– James Rumbaugh
– Ivar Jacobson
• OMG (Object Management Group)
– UML® Resource Page http://www.uml.org/
Usage of UML

• Usage of UML
– 草稿
– 藍圖
– 程式語言
• Rule of UML
– 我們可以在一張特定圖中隱藏任何資訊不顯示
出來。
– 在一張圖中,不可以因為沒有看到某個東西就
做出任何推論。
Meta Modeling
Diagrams Overview (UML 2.0)
Structure Diagram

• Class Diagram [High]


• Component Diagram [Medium]
• Deployment Diagram [Medium]
• Object Diagram [Low]
• Package Diagram [Low]
• Composite Structure Diagram [Low]
Class Diagram

• Attribute ( 屬性 )
– visibility name : type [multiplicity] = default-
value { property-string }
• Operation ( 操作 )
– visibility name ( parameter-list ) : return-type
{ property-string }
– Parameter-list
• direction name : type = default-value
Class Diagram (Cont.)

• Visibility ( 可見性 ) • Multiplicity ( 多重


– + Public ( 公開 ) 性)
– # Protected ( 保護 ) – [Low .. High]
– - Private ( 私有 ) • * / 0 .. *
– ~ Package ( 套件 ) • ? / 0 .. 1
• + / 1 .. *
• / Derived ( 衍生 )
Class Diagram (Cont.)

• Property-string • Direction
– query – in
– modify – out
– readOnly – inout
– frozen
Class Diagram (Cont.)
Stereo Type
Static Type

Class Name

Note
Default Value

Multiplicity

Abstract

Visibility Parameters Direction Return Type


Class Diagram (Cont.)

• Relationship ( 關係 )
– Dependency ( 依賴 , use-a)
– Association ( 關聯 )
• Unidirectional association ( 單向關聯 )
• Bidirectional association ( 雙向關聯 )
• Navigation ( 遊走性 )
– Aggregation ( 聚合 , has-a)
– Composition ( 合成 , owns-a)
– Generalization ( 一般化 , is-a)
• Realization ( 實現 )
Class Diagram (Cont.)

• Association Class ( 關連類別 )


• Stereotype ( 造型輯 )
• Interface ( 介面 ) and Abstract ( 抽象類別 )
• Static ( 靜態 )
Class Diagram (Cont.)

Association Class Class


Generalization

Association Abstract Class


Dependence

Unidirectional
Relation Name
Multiplicity
Bidirectional
Realization

Navigation Aggregation Composition


Class Diagram (Cont.)
Class Diagram (Cont.)

• Qualified Association ( 限定關聯 )


• Template Class ( 樣版類別 )
• Enumeration ( 列舉 )
• Active Class ( 主動類別 )
Class Diagram (Cont.)
Class Diagram (Cont.)

• 使用時機
– 描述系統中各種物件的型態
– 描述各物件之間的靜態關係
– 描述物件的性質與操作
• 使用建議
– 不要畫出包含所有東西的模型,將重點放在關
鍵地方
Component Diagram

• 外部觀點 ( 黑箱觀點 )
– Required Interface ( 需求介面 )
– Provided Interface ( 可提供介面 )
– Artifacts ( 工作成果 )
• 內部觀點 ( 白箱觀點 )
– Realization ( 實現 )
• Port
Component Diagram (Cont.)
Component

Provided Interface

Port
Required Interface

Artifacts
Component Diagram (Cont.)

• 使用時機
– 描述元件之間的交互作用
– 將元件分解成更下層結構時
Deployment Diagram

• Communication Path ( 通訊通道 )


• Node ( 節點 )
– Device Node ( 裝置節點 )
– Execution Environment Node ( 執行環境節點 )
• Artifact ( 工作成果 )
Deployment Diagram (Cont.)

Device Node

Execution Environment Node

Artifact Communication Path


Deployment Diagram (Cont.)

• 使用時機
– 呈現系統的實體配置情形
Behavior Diagram

• Activity Diagram [High]


• State Machine Diagram [Medium]
• Use Case Diagram [Medium]
• Interaction Diagram
– Sequence Diagram [High]
– Communication Diagram [Low]
– Interaction Overview Diagram [Low]
– Timing Diagram [Low]
Activity Diagram

• Initial node ( 初始節點 )


• Activity final ( 活動結束節點 )
• Flow/Edge ( 活動流 / 活動前緣 )
• Incoming Flow ( 進入流 )
• Outgoing Flow ( 離開流 )
• Action ( 動作 )
– 一個動作最好只有一個 Incoming Flow 及一個
Outgoing Flow
Activity Diagram (Cont.)

• Fork ( 分岔節點 )
– 一個 Incoming Flow
– 多個 Outgoing Flow
• Join ( 會合節點 )
– 多個 Incoming Flow
– 一個 Outgoing Flow
Activity Diagram (Cont.)

• Decision/Branch ( 決策節點 / 分支節點 )


– 一個 Incoming Flow
– 多個帶有成立條件的 Outgoing Flow
– 只能有一個 Outgoing Flow 發生
• Merge ( 合併節點 )
– 多個 Input Flow
– 一個 Output Flow
Activity Diagram (Cont.)

Initial node

Flow
Edge Activity final

Fork
Join

Action Decision Merge


Activity Diagram (Cont.)

• Subactivity ( 子活動 )
• Partition ( 分割 )
• Signal ( 信號 )
• Connector ( 連接器 )
• Flow Final ( 活動流結束節點 )
Activity Diagram (Cont.)

Subactivity
Activity Diagram (Cont.)

Partition Connector

Send Signal

Flow Final

Receive Signal
Activity Diagram (Cont.)

• 使用時機
– 描述程式邏輯、企業流程與工作流程
– 描述平行流程
– 描述物件橫跨幾個使用案例或執行緒的行為
State Machine Diagram

• Initial Pseudostate ( 初始虛擬狀態 )


• Final state ( 結束狀態 )
• State ( 狀態 )
• Transition ( 轉換動作 )
• Trigger ( 觸發事件 )
– Trigger-Signature [Guard]/Activity
– Trigger-Signature ( 行為識別資料 )
– Guard ( 成立條件 )
State Machine Diagram (Cont.)

Trigger-Signature Guard Activity

Final State

Initial Pseudostate

Transition

State
State Machine Diagram (Cont.)

• Internal Activity ( 內部活動 )


– Entry Activity ( 入口活動 )
– Exit Activity ( 出口活動 )
– Do Activity ( 持續進行活動 )
• Superstate ( 超狀態 )
– Substate ( 子狀態 )
– History Pseudostate ( 歷史虛擬狀態 )
• 深層歷史虛擬狀態
• 淺層歷史虛擬狀態
State Machine Diagram (Cont.)

Entry Activity

Do Activity

Superstate Exit Activity

Substate

History Pseudostate
State Machine Diagram (Cont.)

• 使用時機
– 描述物件橫跨幾個使用案例的行為
– 了解控制物件行為
• 使用建議
– 不要對每個類別畫出狀態圖
Use Case Diagram

• Actor ( 參與者 )
• Use Case ( 使用案例 )
– Include ( 包含關係 )
– Extend ( 擴充關係 )
Use Case Diagram (Cont.)

Use Case

Actor
Use Case Diagram (Cont.)

• 使用時機
– 了解系統需求
• 使用建議
– 使用案例代表的是外部觀點,不一定會與系統
實作有關連
– 使用使用案例應該將重點放在說明文字而不是
圖上,說明文字才是使用案例價值所在
Sequence Diagram

• Participant ( 參與物件 )
• Lifeline ( 生命線 )
• Message ( 訊息 )
– Synchronous Message ( 同步訊息 )
– Asynchronous Message ( 非同步訊息 )
– Found Message ( 來源不明訊息 )
– Lost Message ( 目標不明訊息 )
Sequence Diagram (Cont.)

Life Line

Found Message

Create Message Synchronous Message


Lost Message

Return
Asynchronous Message

Destroy Message
Sequence Diagram (Cont.)

• 使用時機
– 描述數個物件在某個使用案例中的行為
– 描述物件間的合作關係
• 使用建議
– 要了解多個彼此可替代的互動情形時可以使用
CRC Card
CRC Card

• CRC
– Class 類別
– Responsibility 責任
– Collaborator 合作
Tools

• Free
– StarUML
• http://staruml.sourceforge.net/en/
– ArgoUML
• http://argouml.tigris.org/
– Astah* Community (JUDE)
• http://astah.change-vision.com/en/product/astah-
community.html
– Visual Paradigm - 智宇大大推薦
• http://www.visual-
paradigm.com/solution/freeumltool/
Discuss

Q and A

You might also like