1

In the MVC pattern, is it good programming practice to make all instance variables in the view(GUI) public so that the controller has easier access?

I started to make setters and getters for everything but then gave up because it was way too many. Why does everything have to always be private anyway?

William
  • 169
  • 1
  • 5
  • What programming language are you using? C# makes this trivial by providing auto-implemented getters and setters. – Robert Harvey Dec 26 '16 at 16:31
  • In Java. And it isn't just making setters and getters thats a pain, but having to use them makes code cumbersome in the controller, especially if you have a more complex GUI interface with a lot of components. – William Dec 26 '16 at 16:36
  • 1
    There are costs to avoiding getters and setters. Javabeans requires them, so public members won't work. If you ever have to convert a public member to a gettter/setter, it's a breaking change. Make yourself some tools like an editor macro or somesuch, so that you can reduce the typing involved. – Robert Harvey Dec 26 '16 at 16:53
  • 1
    This is a reasonable question, pointing out that MVC goes against some tenets of OOP. No great answer, but try to avoid public setters as much as possible. – user949300 Dec 27 '16 at 06:34

0 Answers0