views:

53

answers:

1

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?

+1  A: 

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.

TandemAdam