简体   繁体   中英

Are packages allowed in UML 2.0 class diagrams?

I'm designing the classes of a java based system using UML 2.0 notation for class diagrams (with Astah).

In order to simplify dependencies among classes, I would like to group some classes in a package and put dependency relationships from some other classes to the package.

Is putting packages in a class diagram, and then writing relationship between classes and packages, compliant with UML 2.0 specifications?

Should packages be put only in package diagrams?

Firstly, the various diagrams in UML ("Class Diagram", "Package Diagram", "Sequence Diagram", etc.) are more of a conceptual convenience, rather than restriction on what you can visualize, as noted in Annex 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 (eg, showing a state machine nested inside an internal structure). Consequently, the boundaries between the various kinds of diagram types are not strictly enforced.

This means that you can safely put packages in class diagrams and vice versa, because those terms do not mean much.

The more important question however is, whether there can be a dependency between classes and packages, and according to specs we can:

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.

Since both Class and Package are subclasses of NamedElement , you can have a Dependency between them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM