UML 细节
用例图
泛化(generalization):泛化关系是一种继承关系,子用例将继承基用例的所有行为,关系和通信关系,也就是说在任何使用基用例的地方都可以用子用例来代替。泛化关系在用例图中使用空心的箭头表示,箭头方向从子用例指向基用例。
扩展(extend): extend关系是对基用例的扩展,基用例是一个完整的用例,即使没有子用例的参与,也可以完成一个完整的功能。extend的基用例中将存在一个扩展点,只有当扩展点被激活时,子用例才会被执行。 extend关系在用例图中使用带箭头的虚线表示(在线上标注<
包含(include): include为包含关系,当两个或多个用例中共用一组相同的动作,这时可以将这组相同的动作抽出来作为一个独立的子用例,供多个基用例所共享。因为子用例被抽出,基用例并非一个完整的用例,所以include关系中的基用例必须和子用例一起使用才够完整,子用例也必然被执行。include关系在用例图中使用带箭头的虚线表示(在线上标注<
注意,被扩展的用例是原用例,是被 extends 指向的,而如果它包含其他用例,则使用 includes 指向别的用例。
类图
依赖和联系的区别
In general, you use an association to represent something like a field
in a class. The link is always there, in that you can always ask an
order for its customer. It need not actually be a field, if you are
modeling from a more interface perspective, it can just indicate the
presence of a method that will return the order’s customer.
简而言之,一个类中的一个字段,或者一个 getter 意味着联系。
To quote from the 3rd edition of UML Distilled (now just out) “a
dependency exists between two elements if changes to the definition of
one element (the supplier) may cause changes to the other (the
client)”. This is a very vague and general relationship, which is why
the UML has a host of stereotypes for different forms of dependency.
In code terms, such things as naming a parameter type and creating an
object in a temporary variable imply a dependency.You don’t want to show every dependency on a UML diagram - there are
far too many. You need to be very selective and show only those that
are important to whatever it is you are communicating.I tend not to use stereotypes on the dependencies very often. I find
that most of the time the key point I want to show is that a
dependency exists, and which kind is rather less vital.Associations also imply dependency, if there is an association between
two classes, there is also a dependency. But I can’t imagine a case
where you would show that dependency as an extra line on the diagram.
The association implies it, as does a generalization.
模糊地说,client 依赖 supplier,意味着 supplier 的变动会传递到 client 上。
方法参数或者临时变量意味着为依赖。
依赖有很多形式,难以尽述。联系本身也是一种大致的依赖。