rspec/rules/S1104/description.adoc

8 lines
466 B
Plaintext

Public fields in public classes do not respect the encapsulation principle and have three main disadvantages:
* Additional behavior such as validation cannot be added.
* The internal representation is exposed, and cannot be changed afterwards.
* Member values are subject to change from anywhere in the code and may not meet the programmer's assumptions.
To prevent unauthorized modifications, private attributes and accessor methods (set and get) should be used.