What's the purpose of getting/setting values when you can just reassign the value? Is it just because you can get/set private variables?
Asked
Active
Viewed 565 times
1 Answers
1
Using getters and setters is the same as having a method that reassigns a passed value, except it is a formal way of doing it. When you have a getter/setter, the programmer will have expectations on how it will work. Usually they have no major side-effects.
Also refer to this question - Why use getters and setters? - for reasons why to use getters and setters at all.
Community
- 1
- 1
Adam Harte
- 10,369
- 7
- 52
- 85