+ 5
Encapsulation
If the variables of one class are hidden from other classes, and accessible only through the methods of the current class, why are PUBLIC setter methods provided?(it can modify the variable from outside the class then, which makes hiding the variable rather useless??)
1 Odpowiedź
- 5
You realized something good, just because it's valid, doesn't mean it's a good practice! To keep things modular, it's good practice to never declare a setter as public, and your setters should validate data before inserting them into a variable, this way your business rules doesn't get messed up