Model View Presenter (MVP) What is the model?

The Model is normally the group of classes/types/components that represent the core domain (business or otherwise) that your application operates within. These are the classes that perform the key logic required, often in the form of business rules, and also consume/manipulate data In your layered example, the Model would mostly be found in the Domain layer but could also be in the Application layer I think you're having difficulty understanding it because you are trying to combine two separate architectural patterns, or ways of looking at the application, being n-tier/n-layer versus MVP It's completely reasonable (and quite common) to use some sort of Model/View approach while at the same time applying layering in your application Maybe you should focus on them one at a time to start with and then overlay them when you are more familiar with both.

The Model is normally the group of classes/types/components that represent the core domain (business or otherwise) that your application operates within. These are the classes that perform the key logic required, often in the form of business rules, and also consume/manipulate data. In your layered example, the Model would mostly be found in the Domain layer but could also be in the Application layer.

I think you're having difficulty understanding it because you are trying to combine two separate architectural patterns, or ways of looking at the application, being n-tier/n-layer versus MVP. It's completely reasonable (and quite common) to use some sort of Model/View approach while at the same time applying layering in your application. Maybe you should focus on them one at a time to start with and then overlay them when you are more familiar with both.

– David Dec 15 '09 at 14:20 1 Models are all about data. Any logic they contain pertains to the data and its integrity. They shouldn't contain view or controller logic (how to display model contents or what models should be presented to the view in response to user input).

– Will? Dec 15 '09 at 14:26 @David, No, to be honest I have misread MVP for the more general MVC. MVP is all about your UI as far as I am aware.

I actually find the reuse of Model in these various patterns annoying. For the most widely agreed definiton of Model you should have a look at Patterns of Enterpise Applkication Architecture by Martin Fowler. – Ashley Henderson Dec 15 '09 at 14:39 @Will, in MVP it appears that's correct, definitely not in the broader sense of Model View Controller.

But this is exactly why David why asked the question. Eveyone and their dog has come up with a definition of Model these days. I usually go by Martin Fowlers book (see previous comemnt).

– Ashley Henderson Dec 15 '09 at 14:42.

In any of the Model-View-* architectures, the Model is what describes the data in your application (and, if they fit the need, are passed in to the View for rendering). If your application already has Domain objects, it very well may be the case that you could use them for your Model.

– David Dec 15 '09 at 14:10 By "fit the need" I meant if they express the data you need to render in your views. If not, the problem could easily be solved by using View Models...which are pretty much Models meant specifically for expressing data to render in Views. – Justin Niessner Dec 15 '09 at 14:21 Who would be responsible for creating these View Models?

Are View Models the same as what I've seen referred to as screen DTOs? – David Dec 15 '09 at 14:32 I would assume the View Model would be a functional equivalent to a screen DTO.As for who should be responsible for creating them...it all depends on your team structure. I'd say whoever is creating the View should be responsible for creating the View Model since they're the ones who are going to use/consume it.

– Justin Niessner Dec 15 '09 at 14:51 Appologies for not being clear on my last comment.By responsible I was meaning in terms of what would be responsible. Would it be the presenters responsibilty to put together the View Model. – David Dec 15 '09 at 15:34.

The model is the data. This might just be data out of a database in DataSets, or it might be a complete domain model with objects representing your field of business. The view is the UI, whether web pages or a Windows application or a mobile device application.

The presenter is the glue between the two and the brains of the whole outfit. Actions initiated by the view take place in the presenter. Generally in a WinForms application, for instance, a Button.

Click event in my View simply calls a method on the Presenter, which then takes whatever action is necessary (and it may just be doing something back in the View). The presenter holds a reference to the view (through an interface), and to the model. The view has a reference to the presenter (usually I strongly-type this, but it can be an interface as well).

The model doesn't know about the presenter or the view.

Is it the presenter that would then determine for example if a button was enabled/disabled based upon some logic surrounding the state of the model – David Dec 15 '09 at 14:24 In general, yes. I'm not above doing things all in the view on occasion where there are two interdependent parts of the view that have no connection with the presenter or the model. I think the best rule of thumb on that is whether the thing being done would need to be done in any UI (in which case it should be done from the presenter) or whether it's specific to the particular type of UI you're using (e.g. Something you'd do in WinForms but not in WPF).

– Kyralessa Dec 15 '09 at 14:38.

It doesn't matter what architectural guidelines you're following, M is always going to be the same thing. The Model is the piece that is specific to your domain. It's the part that really is what you're application is trying to do.

The Model is supposed to represent your business domain. This goes for MVP, MVC, MVVM, etc. If you were making a inventory system, then an Inventory class would most likely be in your Model, a Product would probably be there, an Order, you get the idea. These are the things that compose your domain logic.

Model–view–presenter (MVP) is a derivative of the model–view–controller (MVC) software pattern, also used mostly for building user interfaces. In MVP the presenter assumes the functionality of the "middle-man" (played by the controller in MVC). In MVP, all presentation logic is pushed to the presenter.

1 Eventually, the model becomes strictly a domain model. The model is an interface defining the data to be displayed or otherwise acted upon in the user interface. The view is a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.

The presenter acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view. Normally, the view implementation instantiates the concrete presenter object, providing a reference to itself.

The degree of logic permitted in the view varies among different implementations. At one extreme, the view is entirely passive, forwarding all interaction operations to the presenter. In this formulation, when a user triggers an event method of the view, it does nothing but invokes a method of the presenter that has no parameters and no return value.

The presenter then retrieves data from the view through methods defined by the view interface. Finally, the presenter operates on the model and updates the view with the results of the operation. Other versions of model-view-presenter allow some latitude with respect to which class handles a particular interaction, event, or command.

This is often more suitable for web-based architectures, where the view, which executes on a client's browser, may be the best place to handle a particular interaction or command. From a layering point of view, the presenter class might be considered as belonging to the application layer in a multilayered architecture system with common layers, but it can also be seen as a presenter layer of its own between the application layer and the user interface layer. The model-view-presenter software pattern originated in the early 1990s at Taligent, a joint venture of Apple, HP, and IBM, and was the underlying programming model for application development in Taligent's C++-based CommonPoint environment.

The pattern was later migrated by Taligent to Java and popularized in a paper by Taligent CTO Mike Potel. 2 After Taligent's demise in 1997, Andy Bower and Blair McGlashan of Dolphin Smalltalk adapted the MVP pattern to form the basis for their Smalltalk user interface framework.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions