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)

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.


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.