I decided to figure out how to work using the MVP template and now I found such an article in Habré.

The bottom line is that presnter , as control levers, 2 interfaces are transmitted one per view (View) and the other per module (DB).

When creating a view , an object is created presnter -a and these 2 links to the interfaces View and Module transferred to it ...

In the article that I pointed out at the link above, this is the code for the class presnter

 public class presenter { IView view; IDataBase dataBase; int Id; public presenter(IView view, IDataBase dataBase) { this.view = view; this.dataBase = dataDase; id = view.getId(); string name = dataBase.loadFromDB(id); view.setName(name); } public onSave() { string name = view.getName(); dataBase.saveToDB(id, name); } } 

So the question is:

I understand that View when created, implements the IView interface, creates an instance of the presenter and passes it a link to the already implemented IView interface, but where IDataBase View take a link to the IDataBase interface that also needs to be passed when creating the presenter ?

  • I think the error in the article. Since the view should not know anything about the model and database. Presenter must initialize the database implementation object dataBase = new DatabaseImpl(); The author of this article is rather doubtful. He even names classes with a small letter, which is not prohibited, but is considered bad form - miha_dev

1 answer 1

IDataBase is a mock object that is needed for testing and only. It involves working with the database. In the application, you can create an object for working with the database in the presenter designer. And in this example, it turns out that the view layer creates an IDataBase and passes it to the presenter.