3
votes

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?

1
I guess you mean wiring rather than writing relationships?qwerty_so

1 Answers

6
votes

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 (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.

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.