Model View Presenter (MVP)

Three components

  • View - UI / how the information is displayed. Fires events to the presenter

  • Model - data/business entities

  • Presenter -


The main difference between this and the Model View Controller is that the presenter refers back to the view
There are two variations:
Passive View - reduces the behaviour of the UI to the absolute minimum by using a Presenter that handles user events and updates the view
Supervising Controller - handles input responses and more complex view logic


Exactly how you structure the code is up to you and there are endless variations.
The layout and structure defined below is designed to help you understand how this pattern actually works.


Create the Model View Presenter base classes

Create another folder to your project called "MVP"
SS


Create the following 4 classes in this folder:
BS_EventArgs -
BS_EventsCollection -
BS_GenericEvent -
BS_PassiveView -


BS_EventArgs

Right mouse click on this new folder in the Solution Explorer and select (Add > Class)
This will display the "Add New Item" dialog box
Change the name to "BS_EventArgs.cs" and press Add
Add the following code


BS_GenericEvent

Right mouse click on this new folder in the Solution Explorer and select (Add > Class)
This will display the "Add New Item" dialog box
Change the name to "BS_EventArgs.cs" and press Add
Add the following code


BS_PassiveView

Right mouse click on this new folder in the Solution Explorer and select (Add > Class)
This will display the "Add New Item" dialog box
Change the name to "BS_EventArgs.cs" and press Add
Add the following code


BS_EventsCollection

Right mouse click on this new folder in the Solution Explorer and select (Add > Class)
This will display the "Add New Item" dialog box
Change the name to "BS_EventArgs.cs" and press Add
Add the following code


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext