MVC Design Patterns – Who Caches the Data?

design-patternsmvc

I am building a GUI to interface an embedded device to a PC host. The GUI provides control over the device parameters and displays some feedback from it. The GUI also has to emulate some of the device functionality and present it to the user.

I have been advised to use a Model-View-Controller pattern, so that if the device does not acknowledge some command, the the user knows about the ineffectiveness of his actions.

Trouble is, I cannot decide which component(s) should cache data. Example: when a value is printed on the screen, the view clearly has to know it. However, the model also has to know it, as it uses it to calculate other values. Furthermore, the controller also has to know it as, for example, the value change could be proportional to a logarithm of the user action.

How do I pull this off properly?

Best Answer

The view has to know it only in a way of how to show the information to the user. It doesn't really know whether it is a weather temperature, some random text, or anything else. It doesn't interpret data in any way.

The model is the one that stores and process data. And it knows whether to enable or disable a control. In your case, you need to cache data in the model.

The controller controls model and view layers. It is the one that can enable or disable a control in the view by using the value from the model. And it sets all the values in the view by just passing them from the model.