Professional Documents
Culture Documents
UML 的 4+1 觀點
UML 的模型觀點,主要取決不同使用者是
用那種觀點來檢視系統的結果,以及每個觀點的
設計考量為何。
圖示類別 適用者
使用個案圖、活動圖 使用者、設計人員、發展人員、測
試人員
類別圖、狀態圖、循序圖、合作圖、活動圖 設計人員、發展人員
元件圖 發展人員
狀態圖、循序圖、合作圖、活動圖,元件圖、配 發展人員、整合人員
置圖
配置圖 發展人員、整合人員、測試人員
RUP 模式生命週期
階段、目標與里程碑
初始階段
目標:
瞭解專案範圍 建立企業個案 取得有關人員對推展該專案的認同
里程碑:完成專案生命週期目標
詳述階段
目標:
降低主要技術之風險 創造系統基本結構 瞭解用何資源以建構系統
里程碑:完成生命週期結構
建構階段
目標:
建構與演化可運作的系統版本
里程碑:初步可運作的系統版本 (常稱為 β 版)
轉移階段
目標:
建立最終版本的軟體系統,並移交給客戶
里程碑:完成軟體產品出版
使用案例圖 (Use Case Diagram)
何謂使用案例圖:
使用案例圖 (Use Case Diagram ) 主要是描述一個
系統或類別提供給外界之交互作用者的功能。簡單來說就是
說明一個系統的功能及其使用者。
Use-case modeling typically starts early in a project and
continues throughout a system development process.
(2) 行為者(actor)
<<actor>>
name
客戶基本資料管理
訂單處理
送貨處理
書店
業務員
顧客 存貨管理
When to Use Use Cases
• A first pass at use cases should be made
early on. More detailed versions of use
cases should be worked just prior to
developing that use case.
Class Diagram
– 何謂類別圖:
類別圖是模型建構技術的重要核心,用來描述一個系統
的靜態結構以及存在類別之間各樣的靜態關係 (static
relationships) 。
– 使用目的
主要是用來將一群有相同特質的概念或實體模組化。
類別圖的主要元素
圖示 意義
(1) 類別(class)
(2) 結合關係
(associations)
(3) 角色(Role)
角色
(4) 限制條件(constraint)
{限制條件}
(5) 修飾詞 修飾詞(qualifier)
(6) 反射(Reflexive)
(7) 繼承關係(Inheritance)
(8) 組合關係c
( omposition)
可改變的組合
不可改變的組合
類別
– 類別的涵意就是將物件經過分類或是抽像化的結果
,剔除物件間的差異只考慮相同的特性。
– 每個類別都有其屬性和其所產生的操作或稱方法。
– 我們把具有共同性質的物件集合稱作類別 (class) ,
並且為每一類別取一個適當的名字。
– 物件被稱作它們所屬別的實例 (instance) 。從某種
觀點來看,其實類別也是一個具有標識的實體,也
是物件的一種。
– 例如,人就是一種類別,屬性有姓名、年齡、身高
、體重…所產生的動作有 、看書、吃飯…。
類別的表示方法
名稱 (name)
屬性 (attribute)
操作方法
(operation)
其它…
Attributes
新增()
刪除()
修改()
類別操作 列印()
Associations
• 結合表示類別與類別之間的關聯及彼此
有結構上的關係。
• An association is a solid line between two
classes, directed from the source class to the
target class
• The name of the property goes at the target
end of the association, together with its
multiplicity
• The target end of the association links to the
Bidirectional Associations
• A bidirectional association is a pair of properties
that are linked together as inverses
• Car class has property owner:Person[1], and the
Person class has a property cars:Car[*].
• The inverse link between them implies that if you
follow both properties, you should get back to a
set that contains your starting point.
• like to label an association by using a verb
phrase (Figure 3.5)
Association
教師 1..* *..1 學生
單項關係
若要強調類別之間的關係是單項的 ,則可以箭頭來表示 。範例如下
顧客 訂單
姓名 * 1 訂單編號
性別 價格
信用狀況 發送 ( )
• Optional implies a lower bound of 0.
• Mandatory implies a lower bound of 1 or
possibly more.
• Single-valued implies an upper bound of
1.
• Multivalued implies an upper bound of
more than 1: usually *.
• If the ordering of the orders in association
has meaning, you need to add {ordered}
to the association end.
• If you want to allow duplicates, add
{nonunique}.
• (If you want to explicitly show the default,
you can use {unordered} and {unique}.)
Operations
• Operations are the actions that a class
knows to carry out .
• Operations most obviously correspond to
the methods on a class.
• Normally, you don't show those operations
that simply manipulate properties,
because they can usually be inferred.
• visibility name (parameter-list) : return-type {property-
string} .
• This visibility marker is public (+) or private (-); protected
(#), package(~).
• The name is a string.
• The parameter-list is the list of parameters for the
operation.
• The return-type is the type of the returned value, if there
is one.
• The property-string indicates property values that apply
to the given operation
• The parameters in the parameter list are notated
in a similar way to attributes. The form is:
• direction name: type = default value
• The name, type, and default value are the same
as for attributes.
• The direction indicates whether the parameter is
input (in), output (out) or both (inout). If no
direction is shown, it's assumed to be in.
• An example operation on account might be:
+ balanceOn (date: Date) : Money
• UML defines a query as an operation that gets a
value from a class without changing the system
state.
• You can mark such an operation with the
property string {query}.
• I refer to operations that do change state as
modifiers, also called commands.
• A getting method returns a value from a field.
• A setting method puts a value into a field.
• An operation is something that is invoked on an
object—the procedure declaration—
• whereas a method is the body of a procedure.
• The two are different when you have
polymorphism.
• If you have a supertype with three subtypes,
each of which overrides the supertype's getPrice
operation, you have one operation and four
methods that implement it.
Generalization
• With a software perspective, the obvious
interpretation is inheritance .
Inheritance (contd)
• Credit Card Class and Debit Card Class
are both subclasses of class Bank Card
Class
Notes and Comments
• Notes are comments in the diagrams.
Notes can stand on their own, or they can
be linked with a dashed line to the
elements they are commenting (Figure 3.6
).
Example: Bank Account Class
• public operations deposit and withdraw can be
invoked from anywhere in the information
system
Dependency
• A dependency exists between two elements if
changes to the definition of one element (the
supplier) may cause changes to the other (the
client).
• A dependency is shown as a dashed-line path
from the source element to the target element
• Many UML relationships imply a dependency.
The navigable association from Order to
Customer in Figure 3.1 means that Order is
dependent on Customer. A subclass is
dependent on its superclass but not vice versa.
• Your general rule should be to minimize
dependencies.
• eliminate cycles at a broader level, particularly
between packages.
• Be selective and show dependencies only when
they are directly relevant to the particular topic
that you want to communicate. To understand
and control dependencies, you are best off using
them with package diagrams
• KeywordMeaning
• «call»The source calls an operation in the target.
• «create»The source creates instances of the target.
• «derive»The source is derived from the target.
• «instantiate»The source is an instance of the target. (Note that if the source is a
class, the class itself is an instance of the class class; that is, the target class is a
metaclass).
• «permit»The target allows the source to access the target's private features.
• «realize»The source is an implementation of a specification or interface defined by
the target (page 69).
• «refine»Refinement indicates a relationship between different semantic levels; for
example, the source might be a design class and the target the corresponding
analysis class.
• «substitute»The source is substitutable for the target (page 45).
• «trace»Used to track such things as requirements to classes or how changes in one
model link to changes elsewhere.
• «use»The source requires the target for its implementation.
限制條件 (Constraint)
表示類別之間的關係中存在條件,在 UML 中以 { 條件 } 表示。
班級中可以有許多學生,學生是班級中的成員。
在班級中是以學號來排列學生的次序。一個班級中只有一個班長,
而這個班長也是班上的期中一個學生。如下圖所示:
班級成員
1..* 1
ordered
{ by student ID}
{subset}
學生 班級
1 班長 1
角色 (Role)
角色是用來表示類別與類別之間關係所扮演的角色。例如在家庭父妻關係
中男主人的角色是老公,家庭的女主人角色是老婆,孩子與女主人的母子關係
中 ,角色分別是為兒子與媽媽 。孩子與男主人的父子關係中,角色分別是為兒
子與爸爸。如下圖所示 :
老公 老婆
男主人 女主人
爸爸 媽媽
兒子 兒子
小孩
反射 (Reflexive)
相同類別物件之間的關係,例如教師必須實習教學課程後才成為正式
的教師。如下圖所示:
教師 實習教學
組合 / 彙總 (aggregation)
組合關係表示物件與物件之間擁有部分 (part-
of) 和被包含於 (contained) 的關係,表示某物件
是由其它若干個物件組合而成,所以合成又稱『組
合』或『集結化』,組合關係是屬於結合關係的一
種特殊。在 UML 中以空心的菱形表示可改變的組合
;以實心的菱形表示不可改變的組合。
Aggregation
• Example: A car is constructed from a
chassis, engine, wheels, and seats
可改變的組合
公車是由司機與乘客所組成,司機是公車的一部分。
公車若沒了司機或乘客,還是公車,所以公車與司機、
公車與乘客之間的關係是可改變的。如下圖所示:
1 1 司機
公車 1 0..*
乘客
Composition
汔車是由 4 個車輪所組成,車輪是汔車的一部分。
汔車若沒了車輪,就不是汔車,可能要改名為”三
輪車”了。所以汔車與車輪之間的關係是不可改變
的。如下圖所示:
汔車 車輪
1
4
When to Use Class Diagrams
• Don't try to use all the notations available to you.
Start with the simple stuff in this chapter:
classes, associations, attributes, generalization,
and constraints
• Don't draw models for everything; instead,
concentrate on the key areas. It is better to have
a few diagrams that you use and keep up to date
than to have many forgotten, obsolete models.
Overview
• Object design is situated between system
design and implementation.
Object design
model after
transformation: User
+email:Address
User LeagueOwner
+email:String +maxNumLeagues:int
+notify(msg:String)
• Mapping Associations
Person SocialSecurity
number:String
Person
SSN:String
Delaying expensive computations
Object design model before transformation
Image
filename:String
data:byte[]
paint()
image
ImageProxy RealImage
1 0..1
filename:String data:byte[]
paint() paint()
Agenda
• Overview
• Mapping Associations
Advertiser 1 1
Account
* *
League Player
nickName
Statistics
+getAverageStat(name)
+getTotalStat(name)
+updateStats(match)
Tournament Player
* *
+getAverageStat(name)
+getTotalStat(name)
+updateStats(match)
1 1
Tournament Player
* *
Agenda
• Overview
• Mapping Associations