Visibility in UML
Visibility allows to constrain the usage of a named element, either in namespaces or in access to the element. It is used with classes, packages, generalizations, element import, package import.
UML has the following types of visibility:
- public
- package
- protected
- private
Note, that if a named element is not owned by any namespace, then it does not have a visibility.
A public element is visible to all elements that can access the contents of the namespace that owns it. Public visibility is represented by '+' literal.
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. Package visibility is represented by '~' literal.
A protected element is visible to elements that have a generalization relationship to the namespace that owns it. Protected visibility is represented by '#' literal.
A private element is only visible inside the namespace that owns it. Private visibility is represented by '-' literal.
Operation executeQuery is public, isPoolable - protected,
getQueryTimeout - with package visibility, and clearWarnings is private.
If some named element appears to have multiple visibilities, for example, by being imported multiple times, public visibility overrides private visibility. If an element is imported twice into the same namespace, once using a public import and another time using a private import, resulting visibility is public.