In Java, we have some modifiers: protected
, public
, private
. In UML, they are #
, +
, -
, respectively.
My question is, what does the ~
symbol mean in UML? And does it have any meaning in Java, C++?
It means package visibility
, which is equivalent to the default access in Java. No analogue in C++.
The UML meaning of the visibility types is given in the description of the VisibilityKind class in the UML Superstructure document (section 7.3.56 in the current v2.4.1 document available at http://www.omg.org/spec/UML/2.4.1).
Package access ~
is
A package element is owned by a namespace that is not a package, and is visible to elements that are in the same package as its owning namespace. Only named elements that are not owned by packages can be marked as having package visibility. Any element marked as having package visibility is visible to all elements within the nearest enclosing package (given that other owning elements have proper visibility). Outside the nearest enclosing package, an element marked as having package visibility is not visible.
This is the same as the default package access in Java (as Alexander said), but note that the UML protected access #
is not the same since, in Java, protected is accessible to the package as well as to subclasses (see, for example, this question). The UML definition is
A protected element is visible to elements that have a generalization relationship to the namespace that owns it.
The key principle is that UML concepts are language-independent, although obviously they're designed to relate to ideas in actual programming languages.