Model View Presenter - Passive View - Who loads the Model?

帅比萌擦擦* 提交于 2020-01-04 01:55:13

问题


I'm curious in using the MVP Pattern to improve testability. I have experience with MVC but MVP seems different.

I'm having an application that operates on a 'project' file which is in fact an compressed archive of several files and folders. This project should be my model.

Where will I put the code that loads the model? I'm also thinking about another abstraction layer: Some kind of BackEndConnection. It will be able to read a project file. It can be an FileBackEndConnection or an FTPConnection or whatever (this should be possible).

Does this belong in the Presenter?

View ---- Presenter ---- Project (Model)
              |
              |
       BackEndConnection

Initilization would be like this:

Presenter presenter = new Presenter(BackEndConnection e);

Will trigger the presenter to call

Project project = backEndConnection.getProject();

and it will be able to initialize the model.

this.model=project;

and then

View v = new View(presenter);

Somehow this sounds wrong. I would rather prefer the BackEndConnection in the Model:

Project --- BackEndconnection

In that case the Presenter will simply intatiate the model with the BackEnd and the model does it's business.

Of course this would mean that the model must offer model.persist() and model.loadFrom(BackEndConnection) and so on. Is this correct? I can't find much ressources on handling model loading regarding MVP.

来源:https://stackoverflow.com/questions/13352704/model-view-presenter-passive-view-who-loads-the-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!