顯示具有 UML 標籤的文章。 顯示所有文章
顯示具有 UML 標籤的文章。 顯示所有文章

2012年9月18日 星期二

UML中的關聯


class之間的關係有以下幾種
1. Association / 關聯 / knows a
X知道Y的存在
X可能以pointer(指標)或reference(參考)知道Y的存在
在概念模型階段方向性(箭頭)通常不太有意義可以省略

2. Dependency / 相依 / use a
A dependency exists between two elements if changes to the definition of one element (the supplier) may cause changes to the other (the client).
X相依Y
Y若改變 X可能會受到影響 但X的改變不會影響到Y
X可能有某個function可以call Y的function
舉個例子:
有一個 class Circle,提供 drawCircle 的功能,然 drawCircle 內部是使用 java 的 graphic 來實作繪圖。則我們可以說:Circle use a graphic. 也就是 Circle 相依於 graphic.

3. Composition / 組合 / has a
car 組合 wheel
Composition是一種整體完全擁有部分
如車子(car)擁有4個輪子(wheel)
當車子(car)消滅時4個輪子(wheel)同時也會消滅

4. Aggregation / 聚合
car 聚合 passenger
Aggregation是一種"擁有性"比較弱的關係
如:
車子(car)裡面有4個人(passenger)
當車子(car)消滅時4個人(passenger)不會消滅

Composition跟Aggregation在意義的差異在於:
Composition是『同生共死』,當System物件死亡時,Component物件也要跟著死亡。Aggregation是『生死有命』,當System物件死亡時,Component物件並不特別去處理。
在C#、Java這類有garbage collection的語言,composition幾乎不會用到,但在C++,只要用到pointer,就得自己去delete,所以在composition對於C++就很重要。


再舉個例子,(from wiki)
a university owns various departments (e.g., chemistry), and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors. In addition, a Professor could work in more than one department, but a department could not be part of more than one university.

5. Inheritance / 繼承 (UML以繼承表示泛型關係)
X繼承Z,Y繼承Z,此時Z和X,Y之間就存在著泛型關係。
Z是共同化(抽象化),X/Y則是特性化(具體化)
如:
BMW / Benz 繼承Car,則Car和BMW / Benx就存在泛型關係

2011年9月27日 星期二

UML筆記---簡介

什麼是UML
字面翻譯:統一塑模語言(Unified Modeling Language)
為了讓所有設計、撰寫軟體的相關人員有共通的語言,達到軟體開發的目標。根據wiki說明,目前UML並非工業標準,但是正在逐漸變成工業標準。UML裡定義了很多圖表讓設計人員,開發人員可以明白系統功能。

常見的圖表可以分成三大類:
結構性圖形(Structure diagrams)強調的是系統式的塑模:
類別圖(Class Diagram)
元件圖(Component diagram)
複合結構圖(Composite structure diagram)
部署圖(Deployment diagram)
物件圖(Object diagram)
套件圖(Package diagram)
剖面圖(Profile diagram)

行為式圖形(Behavior diagrams)強調系統模型中觸發的事件:
活動圖(Activity diagram)
狀態機圖(State Machine diagram)
使用個案圖 (Use Case Diagram)

溝通性圖形(Interaction diagrams)屬於行為圖形的子集合,強調系統模型中的資料流程:
通信圖(Communication diagram)
交互概述圖(Interaction overview diagram) (UML 2.0)
時序圖(Sequence diagram)
時間圖(UML Timing Diagram) (UML 2.0)