Can class visibility be shown on UML class diagrams?
Asked Answered
A

6

9

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.

Albuminoid answered 6/11, 2011 at 22:49 Comment(3)
I don't think UML standard provides specific notation for visibility, because it's a language dependent feature.Servomechanism
Thanks @Heisenbug. I was able to see class visibility on the Enterprise Architect package diagrams. That may be the only way to see it in this particular tool. My next step is to review the relevant part of the UML spec.Albuminoid
I am reasonably certain that a package diagram is indeed the only way to see element visibility (aka Scope) in Enterprise Architect. I won't post it as an answer since you already did the detective work, but please consider doing so yourself (and marking the question answered) for future searchers.Antagonize
M
1

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

Marxismleninism answered 4/2, 2015 at 7:2 Comment(0)
M
0

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.

Marlee answered 7/11, 2011 at 9:22 Comment(0)
S
0

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.

Shackleton answered 7/11, 2011 at 11:55 Comment(2)
Your answer pertains to class-member-visibility, not to the visibility of the class itself.Sestina
@BjörnPollex Visibility is related to some scope, without scope visibility has no meaning. The class instance can be a member of another class instance and in this case its visibility can be seen like shown in this answer.Nugget
U
0

i think you need to have a look at Uni-directional and Bi-directional association

Urion answered 29/11, 2013 at 3:34 Comment(0)
H
0

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.

Hunterhunting answered 3/2, 2015 at 8:36 Comment(0)
U
0

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?

Upsweep answered 10/9, 2015 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.