We recently had an in-class discussion on the issue of attribute visibility in the class diagram. Some have stated that in the diagram (as well as in the code) all attributes must be private. However, the teacher made the following observation: In the class diagram, we represent the visibility of the PROPERTY of the attribute. Here is an example (purely didactic):
private string _CPF;
**public** string CPF {
get { return _CPF; }
private set
{
if (value.Length == 11)
_CPF = value;
}
}
In this case above, according to him, the correct would be to put the attribute (in the diagram) as public (because the property will be public (in bold)). However, in this case, get
is public and set
private, so how do I represent the visibility of the _CPF
attribute in the class diagram?
All the materials I've read speak to put all the attributes in the diagram private, so should I use them all as private or should I put the visibility of the property?