UML 2.0 class 图中是否允许包?
Are packages allowed in UML 2.0 class diagrams?
我正在设计基于 java 的系统的 classes,使用 class 图表的 UML 2.0 符号(使用 Astah)。
为了简化classes之间的依赖关系,我想将一些classes放在一个包中,并将其他classes的依赖关系放入包中。
是不是把包放在class图中,然后写class和包的关系,符合UML 2.0规范?
包应该只放在包图中吗?
首先,UML中的各种图表("Class Diagram"、"Package Diagram"、"Sequence Diagram"等)更多的是概念上的方便,而不是限制你可以想象的内容,如附件 A 所述:
Annex A
This taxonomy provides a logical organization for the various major kinds of diagrams. However, it does not
preclude mixing different kinds of diagram types, as one might do when one combines structural and behavioral
elements (e.g., showing a state machine nested inside an internal structure). Consequently, the boundaries between the
various kinds of diagram types are not strictly enforced.
这意味着您可以安全地将包放在 class 图中,反之亦然,因为这些术语意义不大。
然而,更重要的问题是,classes 和包之间是否可以存在依赖关系,根据规范我们可以:
7.7.3.2
A Usage is a Dependency in which one NamedElement requires another NamedElement (or set of NamedElements) for
its full implementation or operation. The Usage does not specify how the client uses the supplier other than the fact that
the supplier is used by the definition or implementation of the client.
因为 Class
和 Package
都是 NamedElement
的子class,所以它们之间可以有一个 Dependency
。
我正在设计基于 java 的系统的 classes,使用 class 图表的 UML 2.0 符号(使用 Astah)。
为了简化classes之间的依赖关系,我想将一些classes放在一个包中,并将其他classes的依赖关系放入包中。
是不是把包放在class图中,然后写class和包的关系,符合UML 2.0规范?
包应该只放在包图中吗?
首先,UML中的各种图表("Class Diagram"、"Package Diagram"、"Sequence Diagram"等)更多的是概念上的方便,而不是限制你可以想象的内容,如附件 A 所述:
Annex A
This taxonomy provides a logical organization for the various major kinds of diagrams. However, it does not preclude mixing different kinds of diagram types, as one might do when one combines structural and behavioral elements (e.g., showing a state machine nested inside an internal structure). Consequently, the boundaries between the various kinds of diagram types are not strictly enforced.
这意味着您可以安全地将包放在 class 图中,反之亦然,因为这些术语意义不大。
然而,更重要的问题是,classes 和包之间是否可以存在依赖关系,根据规范我们可以:
7.7.3.2
A Usage is a Dependency in which one NamedElement requires another NamedElement (or set of NamedElements) for its full implementation or operation. The Usage does not specify how the client uses the supplier other than the fact that the supplier is used by the definition or implementation of the client.
因为 Class
和 Package
都是 NamedElement
的子class,所以它们之间可以有一个 Dependency
。