There seem to be some varying opinions as to where to store non-persisted state: model or controller. I’ve collected some of the opinions below:
Models represent persisted state on the server … strictly server-persisted state
I imagine a property like “fullName” could be used in more than one place across your application (and having this in the controller would force you to duplicate the effort across different parts of the app)
the place where you draw the line on controller and model is wishy washy. If the property needs to persist across controllers then you should add it to the model, especially if the controller isn’t a singleton controller. If it’s a singleton controller and the model never changes underneath it, then the property can live on the controller.
With @ebryn’s approach—using models exclusively for persisted-state—I found it tricky to ensure that each view context was backed by the same controller instance (particularly when using
itemController in various parts*). So I’m beginning to feel that it may make sense to use the model for some non-persisted properties, as @toranb and @kingpin2k have suggested. Are there any arguments against using the model in this way?
*(FWIW: I had an
isActive property on a controller that needed to be displayed in various views.)