开发者

model-view-presenter: where to persist "UI" data?

I build a WinForm application using the MVP pattern.

My model is an hierarchical tree of f开发者_高级运维olders and files. My view has a tree view to show it.

I now face the requirement to "remember" which nodes in the UI tree were expanded in the last session.

This information does not feel to belong in the file system model. or does it? and if this is presenter logic does it mean I need to persist my presenter also?


No, you should not persist your presenter, you should have a configuration/settings/appdata file where you can store that information, after all is a requirement of your application and you should model it as you'd model anything else.

what I find useful doing is, while the application is in a 'transient' state is to reflect any change that the user does through the View in a model in the presenter; this would mean that everytime a node is expanded, you would inform the presenter about that and update the value of your model. when the user closes the session you persist this model somewhere, a file or a db,etc.

so as a summary,

  • model: holds the domain data, in your case which folder/file was expanded
  • presenter: interacts with the view and the model to reflect those changes in the current model reference.

hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜