Class visibility is an important part of object design. I have not seen any example diagrams showing non-public classes in several UML books, nor have I seen a way to show class visibility in Enterprise Architect, among other tools. Enterprise Architect and other tools allow you to set the class visibility in the metamodel, but I have yet to see a way to show this in the diagrams.
According to the UML spec v2.5 beta 2 not only the NamedElement but also the PackageableElement has the attribute Visibility of type VisibilityKind
from p48:
PackageableElement [Abstract Class]
..[snip]..
Attributes
- visibility : VisibilityKind [0..1] = public A PackageableElement must have a visibility specified if it is owned by a Namespace. The default visibility is public.
Constraints
- namespace_needs_visibility A PackageableElement owned by a Namespace must have a visibility. inv: visibility = null implies namespace = null
I haven't found any notation guidelines for this visibility however
In Eclipse you have the visibility in the icon. I mean that you have a green class icon and if private then a p is put on the top. This icon is also visible in the class diagram if you select the option. Hope this help.
UML supports visibility in a programming language-neutral way, both in the metamodel and in representation.
There's an Enumeration named VisbilityKind that is used in various places (see the UML 2.3 superstructure spec section 7.3.5.5 p142).
On class diagrams there are various ways to illustrate visibility. The most common is to use '-' to represent private features and '+' to represent public. For example:
----------------------------
| Class |
|--------------------------|
| +publicAttribute: Type |
| -privateAttribute: Type |
|--------------------------|
| +publicMethod() |
| -privateMethod() |
----------------------------
See figure 7.28 / 7.29 on p52 of the spec for more examples.
hth.
i think you need to have a look at Uni-directional and Bi-directional association
I just looked it up in the UML 2.4.1 Infrastructure. On figure 10.3 p. 95 you see Class defined as a Type which is a NamedElement which is an Element. With the visibility package a NamedElement has a visibility as defined in 9.21.1 on p. 88, if it belongs to a namespace. So Class has a visibility if you have visibilities. You can use the usual notations with + - # and ~ (p. 89).
VisualParadigm can do this.
If you define your class with a stereotype (say <<class>>) you can then assign a shape-script to the stereotype. If you only specify a decoration, this should use the default drawing for a class, and add your decoration, which can be conditional based on the class's scope property:
decoration X
{
if(hasproperty("scope","public"))
print("P");
}
This prints a P in the top-left corner of a public class. However, you could equally have an icon instead.
Unfortunately, I can't find a way of assigning a shape-script to a default non-stereotyped class. Anyone know how to do that?
© 2022 - 2024 — McMap. All rights reserved.