+ 2

I really do not understand the "property" and the "setter". The "property" makes the attribute read-only, but the "setter" makes the attribute mutable. So if we want to use "property", why we need to introduce the "setter".

21st Apr 2016, 4:34 PM
CooLee - avatar
2 Answers
+ 3
Properties are OOP feature. Mind getter and setter as of events, that occurs transparently when someone access attribute. It may be useful to verify or format value.
28th Apr 2016, 7:35 AM
Andrey Soplevenko
Andrey Soplevenko - avatar
+ 3
it's good to have control over your variables rather than letting them be accessed freely. You may want to, for instance, deny a change in a variable or even call another method in your setter
20th Jun 2016, 8:16 AM
Matheus Fernandes
Matheus Fernandes - avatar