This question already has an answer here:
- When are Getters and Setters Justified 16 answers
I was thinking about encapsulation in Java and then I thought how getters/setters break encapsulation. After I went through this , I saw many recommendations like to avoid getters/setters on fields not necessary, or some policies on how to implement them.
What I failed to understand is in-case of a MVC model, how do getters/setters break encapsulation. Incase if someone wants to take an example MVC framework, I would like to consider Spring-MVC.
So, basically, in MVC the data is manipulated generally by the business code, implementing an interface. The business code is getting orders from Controller, which is not messing with Model at all.
This way, I see that the model is nicely isolated or buried across 2 layers i.e Controller and Business. Can anyone explain me why in an MVC model as well, getters and setters break encapsulation.
I hope my question was clear. If anything is missing, kindly let me know. Thank you.
Perhaps people have not been reading but just flagging around. My question mainly deals with MVC and encapsulation rather than why getter/setters are justified. My point of focus still remains on MVC, that's why I have not accepted the answer.