Model View Presenter - Passive View - Who loads th

2019-07-04 19:26发布

问题:

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.