Java design: too many getters

Posted by dege on Stack Overflow See other posts from Stack Overflow or by dege
Published on 2010-03-20T20:19:34Z Indexed on 2010/03/20 20:21 UTC
Read the original article Hit count: 433

After writing a few lesser programs when learning Java the way I've designed the programs is with Model-View-Control. With using MVC I have a plethora of getter methods in the model for the view to use. It feels that while I gain on using MVC, for every new value added I have to add two new methods in the model which quickly get all cluttered with getter & setters.

So I was thinking, maybe I should use the notifyObserver method that takes an argument. But wouldn't feel very smart to send every value by itself either so I figured, maybe if I send a kind of container with all the values, preferably only those that actually changed. What this would accomplish would be that instead of having a whole lot of getter methods I could just have one method in the model which put all relevant values in the container. Then in the view I would have a method called from the update which extracted the values from the container and assigning them to the correct fields.

I have two questions concerning this.

First: is this actually a viable way to do this. Would you recommend me doing something along these lines?

Secondly: if I do use this plan and I don't want to keep sending fields that didn't actually change. How would I handle that without having to have if statements to check if the value is not null for every single value?

© Stack Overflow or respective owner

Related posts about design

Related posts about model-view-controller