Model-View-Presener(MVP) is a variation of the Model-View-Controller (MVC) architectural pattern for building user interfaces. The main goal of MVP and its variants is separation of concerns between the user interface (UI), the model (application data), and the presenter (controller that handles business/presentation logic). This version of MVP is called passive because the View does not actively update itself, instead choosing to allow the presenter to handle that task.

In MVP, the view and the presenter are tightly coupled with the view holding a reference to the presenter and calling methods from it in response to UI events. The view knows nothing of the existence of the model.

View -> Presenter.

The presenter is fully aware of and holds references to both the Model and the View.

View <- Presenter -> Model.

The model knows nothing about either the view or the presenter. The model has one purpose: to store and retrieve data.

In this example, we'll create a simple form that checks password input. Being that the model is the simplest in this example, let's start there.

Also pretty simple. Our presenter holds a reference to the view and model. It has a login method that is called by and passed an argument from the view in response to login button event. The presenter takes the argument passed in, verifies it with the model, and if the inputted password is the same as the password set in the model, it update the view accordingly.

Our View is the most complicated, but only because of widget creation and layout.

The view holds a reference to the presenter so it can call methods in it. The loginButton calls presenter.login() to start the password verification process. The presenter calls updateStatusLabel() to update the view.

We instantiate the view on the EDT, and to save time, we just set the presenter and instantiate the model there as well. You may not always want to set the presenter and instantiate the model on the edt so as to not cause usability problems with the UI. e.g. a model created from a remote database.