【UML】《Theach yourself uml in 24hours》——hour4

类之间的关系如何表达

一、关联 Associations

拿篮球赛事来举例:
1、球员在某个球队打球
【UML】《Theach yourself uml in 24hours》——hour4
2、可以在关联的下方标注角色(rule)
【UML】《Theach yourself uml in 24hours》——hour4
3、类之间是双向的关联关系
【UML】《Theach yourself uml in 24hours》——hour4
4、多个类之间的关联关系
【UML】《Theach yourself uml in 24hours》——hour4
5、在关联关系上加限制条件
【UML】《Theach yourself uml in 24hours》——hour4
6、“或”的关联关系
【UML】《Theach yourself uml in 24hours》——hour4
7、关联类 Association Classes
一个关联关系也可能有属性和方法,就想类一样。
【UML】《Theach yourself uml in 24hours》——hour4
8、实例之间的关联关系描述
【UML】《Theach yourself uml in 24hours》——hour4
9、多重性 multiplicity 的表示方式
【UML】《Theach yourself uml in 24hours》——hour4
10、当我们询问某个订单信息时,商家需要我们提供订单号来确定哪个订单,此时这个ID在UML中称为qualifier.通过这个id就能让订单列表和订单之间变成一对一的关系。
【UML】《Theach yourself uml in 24hours》——hour4
11、自反的关系 reflexive assocition
情形:一个类和自己有关联关系,这通常发生在一个类有多种不同角色的实例这种情况。比如车上的人可能是司机也可能是乘客:
【UML】《Theach yourself uml in 24hours》——hour4
12、继承和泛化 Inheritance and Generalization
注意下图都是单数形式
【UML】《Theach yourself uml in 24hours》——hour4

一个类使用另一个类这属于依赖关系:
【UML】《Theach yourself uml in 24hours》——hour4
象棋的类图(class diagram)和实例图(object diagram)
【UML】《Theach yourself uml in 24hours》——hour4