1.
两种关联关系的特例:
1)
聚合
Aggregation
——
Aggregation: b can live without its context (object of A).
============================================
==C++==
class B{
B* b;
}
==java==
class B{
B b;
public A(B b){
this.b = b;
}
}
聚合是整体与部分、拥有的关系,即
has-a
的关系,此时整体和部分之间可以分离,他们可以具有各自的生命周期
,部分可以属于多个整体对象,也可以为多个整体对象共享;比如计算机与
CPU
、公司和员工的关系等;表现在代码层面上,和关联关系一致,只能从语义级别区分。
2)
组合
Composition
——
Composition: b's lifetime is up to its context (object of A).
==C++==
class A{
B b;
}
==java==
class A{
B b;
public A(){
b = new B();
}
}
组合也是关联关系的一种特例,他体现一种
contains-a
关系,这种关系比聚合关系更强,也称为强聚合;它同样体现为整体和部分见的关系,但此时整体和部分是不可分割的,
整体的生命周期结束时部分的生命周期也结束
。比如,你和你的大脑。在代码层面上,和关联关系一样,只能从语义级别区分。
2.
几个例子:
演出售票系统
:
在用例驱动的开发过程中,通过分析各个用例及参与者得到类图。分析用例图的过程中需要根据面向对象的原则设计类和关系,根据用例的细节设计类的属性和操作
Composite模式
:
*
从演出售票系统理解
multiplication
的使用——
SubscriptionSeries
和
Ticket
之间的多重性是“
0...1
”和“
3...6
”:
A.
特定的
1
个
SubscriptionSeries
实例,在数据表中找得到它对应的
3...6
张
Ticket
实例;
B.
特定的
3...6
张
Ticket
实例,在数据表中找得到他们对应的
1
个
SubscriptionSeries
;或者
0
个
SubscriptionSeries
,因为可能这些
Ticket
来自
IndividualReservation
- 大小: 15.1 KB
- 大小: 15 KB
- 大小: 23.4 KB
- 大小: 37.9 KB
- 大小: 9.1 KB
- 大小: 27.6 KB
分享到:
相关推荐
C# and UML class diagram,这是有关C#和UML class diagram的一个详细讲解和比较应用
UML class diagram
EXT JS 3.0 Core Class Diagram ext js的核心代码类图
程序设计大作业的类图描述,用于展示各个类之间的关系。方便阅读相关的代码。通过类图可以完成一个程序的总体架构,并对各个架构进行分析和编写。类图还可以展示类的成员,通过点击类的成员可以直接定位到相应代码...
ExtJS_3.0_Class Diagram
AS3classDiagram.airAS3classDiagram.airAS3classDiagram.air
The class diagram of Openlayers, more details please refer to www.openlayers.org
描述QT的类图关系,编程必须掌握的基本概念
Class Diagram0.asta
UML Class Diagram Tutorial and tutorial for dia software
UML簡介_Class Diagram 学习ERD的
as3 类关系图 jpg格式,as3 类关系图 jpg格式,as3 类关系图 jpg格式,as3 类关系图 jpg格式,as3 类关系图 jpg格式
eMule 0.27c Class Diagram.pdf,对eMule源代码的体系结构和类图有详细的介绍,对理解eMule的源码很有帮助
The following class diagram represents a design in factory method pattern to query the features of different types of auto insurances. See the source code for the implementation of the following class...
Qt5类关系图,基于Qt5.1版本,对于系统学习Qt5很有帮助。
Creating_Class_Diagram.swf
UML类图大全
方法代表对象的操作行为,类具有继承关系,可以继承于父类,也可以与其他的Class进行交互。类图展示了系统的逻辑结构,类和接口的关系。二、类的构成类主要有属性和方法构成。比如商品属性有:名称、价格、高度、...
UML知识之二:类图的设计