Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm looking for feedback on MVP and MVC patterns used as a framework to build a website. I've used both with a certain degrees of success and failure. Furthermore I've worked in places which have miserable implement MVP across the web, desktop and services layers. I've also seen a few terrible MVC implementations. One thing I've noticed is the MVP stuff-up appear terrible for maintenance or adding any new features compared to the MVC debacles.

EDIT:

MVP - Model View Presenter http://en.wikipedia.org/wiki/Model-view-presenter

"The View holds a reference to the Presenter. The Presenter is also reacting to events being triggered from the View, so its aware of the View its associated with. The Presenter updates the View based on the requested actions it performs on the Model, but the View is not Model aware."

MVVM pattern was designed to support WPF and Silverlight. It's similar to MVP, in the concept the view doesn't know about the model however its not MVP.

share|improve this question
1  
Of course us Djangoistas would suggest MTV as a viable alternative. :-) docs.djangoproject.com/en/dev/faq/general –  Peter Rowell Jun 21 '11 at 0:33
    
MVP? I've heard of MVVM and MVC, but what is MVP? Could you spell it out somewhere in your question? –  Thomas Owens Jun 21 '11 at 1:02
2  
@Thomas: Model-View-Presenter, en.wikipedia.org/wiki/Model-view-presenter –  Robert Harvey Jun 21 '11 at 1:04
    
@Robert Thanks. Now that I read that, I have heard about it. I was just blanking on what the P could have been. –  Thomas Owens Jun 21 '11 at 1:11
add comment

4 Answers

up vote 3 down vote accepted

I guess you're asking in the context of the Microsoft world?

It was my understanding that MVP was mainly employed for unit testing the controllers of the application. I think another term for the MVP pattern is Supervising Presenter.

The view in this case would be the ASP Page, which would have an instance of the Presenter, and any events in the page (click handler's for example) would delegate their work to the Presenter. The Presenter would have a reference to the View (although, through an IView interface that the Page would implement). The Presenter would then respond to actions from the View, do something, update the model and pass it back to the view or perform actions on the View via the interface.

This aids unit testing, because the Presenter (where any presentation logic should be) can have the view mocked out. Typically a Presenter would also have references to other services, which should rely on dependency injection (via constructor injection IMO) to also allow for the Presenter to be tested in isolation (a proper unit test).

The main reason I think to use MVP in ASP.NET WebForms is because the Page class is tied to the ASP.NET runtime, whereas because ASP.NET MVC has abstractions on things like the HttpRequest, and the controller and ActionResult classes can be tested in isolation, you don't need to employ MVP - it's unit testable by default.

So to answer (I think): I'd use MVP if I was using WebForms, to aid testability. Otherwise I'd use MVC.

Also check out the Web Client Software Factory, which offers a framework for a starter point for implementing the MVP pattern.

share|improve this answer
    
And yeah, MVVM if you're doing WPF/Silverlight, or JavaScript & HTML with knockout.js (or other libraries). –  jamiebarrow Jun 21 '11 at 9:14
    
cheers @jamiebarrow, the web client software factory looks very interesting, thanks for the info and feedback. –  Nickz Jun 21 '11 at 23:36
add comment

Depends on what you're doing. If you're stuck using WebForms, MVP is your only real choice to do things properly with that beast. If you can use MVC, use that, otherwise use MVP or some variation thereof.

share|improve this answer
add comment

There are ways to meld the two. For instance with ASP.NET MVC you can use the regular MVC pattern, but have the Views strongly bound to a ViewModel (as in MVVM, a descendant of MVP). This gives the benefits of MVP (i.e., decoupling the view from the specificities of the domain model) while also having a dedicated layer to handle events.

I haven't tried applying this outside of .NET, however.

share|improve this answer
1  
Cheers for the feedback. I've used MVC in java and .net. While I've used MVP in .net webforms, which I felt was a disaster. –  Nickz Jun 21 '11 at 1:17
1  
@Nick: MVP would be a better fit for Winforms than Webforms, because you don't have to deal with the page life cycle and view-state. –  Robert Harvey Jun 21 '11 at 1:27
    
Yes I agree I'm dumbfounded why the decision was made, which is one of the reasons I'm asking the question. I have minimal experience using MPV with java, .net or any other language unlike MVC. I wanted to know what were others experience using MVP or MVC and the result. Why would use each pattern and when. Cheers @Robert. –  Nickz Jun 21 '11 at 1:44
1  
@Nick: I would not attempt MVP on webforms without some sort of library or framework to help me, like this one: webformsmvp.codeplex.com/releases/view/63338 –  Robert Harvey Jun 21 '11 at 1:47
    
Unfortunately it's probably too late to implement this, the project nearly 2 yrs old. There got a very generic MVP framework, all of the normal web forms controls have been re-written as MVP controls, it very comprehensive and complicated. Cheers @Robert –  Nickz Jun 21 '11 at 2:07
show 2 more comments

At the end of the day which is best is, as always, dependent on what you're developing.

Disclaimer: I haven't really looked into MVP all that much, but from what I've read...

It would seem to me that the MVP model may make sense in an application where the client is responsible for what would otherwise be MVC controller actions such as saving, editing, deleting etc via AJAX (or websockets) - the importance being that the business logic is held within the client-side (view is responsible for) javascript.

Personally, I would consider it poor design if the view (in whatever backend language) itself contained logic for database transactions. I like the decoupling that the MVC pattern offers, making views as stupid as possible. To me, MVP seems to be almost taking a step backwards in development practices.

Just my opinion though :)

share|improve this answer
    
I tend to agree with a few of ur points, MVP (similar to Microsoft's Silverlight/WPF MVVM pattern) creates a lot of events and actions. Which leaves you with another layer of abstraction to the web. Cheers for the feedback. –  Nickz Jun 21 '11 at 1:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.