Fields and Properties
You have seen what a property is and why you need properties. A normal class should have all its attributes implemented using a combination of private fields and public (or friend) properties. In some cases it may be useful to give access to the class fields to classes in the same assembly as itself. In this case you can use friend fields and public properties. That would ensure that no one outside the assembly has access to the class internals.
Using public fields is the only big no-no. It would break the encapsulation principle, which is one of the most important OO principles.
In UML notation, the class attributes normally represent both the property and the field. The attribute specification will indicate whether a combination ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access