+ 1
Why do we need to protect attributes?
Why do we protect attributes in classes? From what exactly? I am the one who writes the code and I can decide if I'm gonna use an attribute and how. How is that even a protection?
1 Answer
+ 3
'never trust in input'
Protecting attributes by using getters and setters allow you to check the datas before modifying an attribute.
It allows too to have read-only attributes.