类图(Class Diagram)是显示出类、接口以及它们之间的静态结构和关系的图。类图最基本的元素是类或接口。
下面最要是类图中一些符号的说明:
类的框架分成以下几层:
类名
属性清单
方法清单
性质清单
(如果有内部成员就会有五层)
类名层:
正体字表示具体的类,斜体表示抽象类。
属性层:
(+):public 、 (-):private 、 (#):protected
方法层:
(+):public 、 (-):private 、 (#):protected 、方法名下有下划线:静态方法
性质层:
性质是由一个属性,一个赋值和一个取值函数构成。
类图中的关系:
一般化关系:从子类指向父类,或实现接口类指向被实现的接口,与继承或实现的方向相反。
关联关系: 从包含类指向被包含的类(eg:Driver类——>Car; Driver类中有Car字段)。
聚合关系:整体与个体之间的关系(特殊的关联关系)。
合成关系:是比聚合关系强的关系,他要求普通的聚合关系中代表整体的对象负责代表部分的对象的生命周期,合成关系不能共享。
依赖关系:表示一个类依赖于另一个类的定义。从这个类指向另一个类。
时序图:又叫序列图、活动序列图。作为交互图的一种,序列交互图按照时间顺序从上往下显示每一个使用案例。
垂直的虚线叫做生命线,它代表一个对象存在的时间。每一个箭头都是一个调用,这个箭头从调用者对象连接到接收者对象的生命线上的激活条(Activation Bar)上。每一个激活条代表调用所持续的时间。
状态图:又称状态转换图(State Transition Diagram)。 基本想法是定义一个具有有限个内部状态的机器。对象被外界的事件激发,从而从一个状态转换到另一个状态。