开发者

Can the Presenter have state? (MVP pattern)

开发者 https://www.devze.com 2023-04-13 02:39 出处:网络
I\'m reading about the Model-View-Presenter pattern, and I\'m a bit confused: can a presenter have state? Or is the task of the Presenter to only group methods together containing business l开发者_Sta

I'm reading about the Model-View-Presenter pattern, and I'm a bit confused: can a presenter have state? Or is the task of the Presenter to only group methods together containing business l开发者_StackOverflowogic, and every state information should be put in the Model?

Here's an example scenario: suppose I have to present a sortable, paged list of items. In this case the View should view the items. The presenter should load the items to be viewed into the model. Where should the 2 state variables (sorting type and the current page index) go, should they be considered the state of the Presenter or part of the model?


This is clearly not an application state but a view state. Not only losing this state won't hurt much but also it does not affect the business logic.

That being said I wouldn't hesitate to place this extra "state" in the presenter or even in the view. You will probably implement this using either HTTP session or client-side cookies - these persistence strategies obviously are targeted for view.

0

精彩评论

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