Are getters and setters evil??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Are getters and setters evil???

So I was talking to someone today and they were telling me that getters and setters are usually to be avoided if possible because it contradicts the principal of oop which is to hide implementation of objects which I get. I’m just curious as to how you guys go about doing that. I’m kind of stuck as to how to put this principal into practice.

4th Jul 2018, 2:58 AM
Haon1919
Haon1919 - avatar
3 Answers
+ 4
its called encapsulation its to keep your class fields private
4th Jul 2018, 6:07 AM
D_Stark
D_Stark - avatar
0
「HAPPY TO HELP」 ahhhh I think I follow. So are saying that get methods and set methods are ok sometimes if the name is soecific but caution is needed because it could possibly cause a sode effect where a child is modifying the parents attributes?
4th Jul 2018, 3:40 AM
Haon1919
Haon1919 - avatar