2023-10-12 18:11:39 +02:00
|
|
|
Public fields in public classes do not respect the encapsulation principle and have three main disadvantages:
|
2020-06-30 12:47:33 +02:00
|
|
|
|
2021-02-02 15:02:10 +01:00
|
|
|
|
2020-06-30 12:47:33 +02:00
|
|
|
* 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.
|
|
|
|
|
2023-10-12 18:11:39 +02:00
|
|
|
To prevent unauthorized modifications, private attributes and accessor methods (set and get) should be used.
|