Visibility

Visibility dictates the accessibility of a member (attribute or operation) and can be designated by placing a notation before the member's name. In general, you want to give only as much accessibility as is needed. The following table details the most common visibility notations:

Notation Visibility Description
+
Public
Member is accessible by other types.
#
Protected
Member is accessible within the same type as well as types that inherit from it.
~
Package
Member is accessible from any type within the same package. It is not accessible from outside the package, even if it is an inheriting class.
-
Private
Member is accessible only within the type that declares it.

 

For example, the following diagram shows the Order class, which has two private attributes, OrderId and OrderDate, as well as two public operations, CalculateTax and CalculateTotal: