
(1) Unidirectional Aggregation
(2) Unidirectional Composition
(3) unidirectional association.
(4) Associations (relationships between classes).
(5) Aggregation (comprises) relationship relationship.1 Destroying the "whole" does not destroy the parts.
(6 ) Composition (has) relationship.1 The parts are destroyed along with the "whole." Doesn't really exist in Java. In C++
結合關係(association)有兩種變形,一種為空心菱形的「聚合關係」(aggregation),另一種為實心菱形的「組合關係」(composition)。聚合或組合關係兩端的物件,一端扮演「整體物件」(whole object,整件),另一端扮演「部分物件」(part object,部件)。在結合關係中,兩端的物件並不具有「整體-部分」(whole-part)的特色。
一般,我們可以透過檢核下列四項要件,判斷兩類別之間採用結合、聚合還是組合較適當:
1. 在企業領域的專業概念裡,兩種物件之間有一種固定不變且需要保存的靜態關係。(結合關係的要件)
2. 在資訊化時,系統會用到這些靜態關係,而且必須將它們存到資料庫。(結合關係的要件)(符合上述要件1~2,即可採用結合關係)
3. 在企業領域的專業概念裡,兩種物件之間有整體-部分的靜態關係。(聚合關係的要件)
(符合上述要件1~3,即可採用聚合關係)
4. 部件只能連結一個整件,且整件被註銷(destroy)時,部件必須一塊被註銷。(組合關係的要件)(符合上述要件1~4,即可採用組合關係)
沒有留言:
張貼留言