Blog Stats
  • Posts - 18
  • Articles - 0
  • Comments - 54
  • Trackbacks - 76

 

Model-View-Presenter split into two "new" patterns

For the past year or so, Martin Fowler has included the pattern Model-View-Presenter, or MVP, in his upcoming addendum to  Patterns of Enterprise Application Development.  Due to apparent confusions between MVC and MVP, Fowler has now split this pattern into what he's calling “Passive View” (http://martinfowler.com/eaaDev/PassiveScreen.html) and “Supervising Controller/Presenter” (http://martinfowler.com/eaaDev/SupervisingPresenter.html).  (Now what am I to do! ;)

Passive View stresses zero/none/nada dependencies between the View and the Model.  Previously, with MVP, the View could be given a dependency to the Model to decrease the amount of communications between the View and the Presenter.  But, from how I understand it, the Controller in Passive View (previously the Presenter in MVP) would now have a dependency on System.Web, in ASP.NET anyway, to facilitate direct communications with the View display elements.  A “Test Double“ could then sit in for the View for unit testing purposes.  Although I really don't like the idea of a controller depending on System.Web, Passive View seems a bit simpler than MVP.  But instead of it depending on System.Web, Fowler suggests the use of a “Gateway“ to avoid the dependency.  The primary disadvantage to Passive View, in ASP.NET, is that it would become much more tedius to bind to a webcontrol, such as the datagrid, if the View has no knowledge of the Model.  I suppose DTOs could be used in their stead.

Alternatively, Supervising Controller looks to be a “flexible” interpretation of the original MVP pattern.  I.e. the View isn't completely dumb and knows how to use a limited amount of the Model.  Supervising Controller leaves the data binding up to the View and only helps out when the logic becomes non-trivial.  I believe this is very similar to how I discussed MVP to be in http://www.codeproject.com/useritems/ModelViewPresenter.asp.  The primary benefit to this pattern is that it makes the presentation logic easy to unit test.  The primary drawback, in my opinion, is that it makes it difficult to draw a clear line between what should go in the View (the code-behind in ASP.NET) and what should go in the Supervising Controller.  Passive View makes the separation of responsibility a bit more clear.

Now off to go update my class PPTs.

Billy


Feedback

# re: Model-View-Presenter split into two "new" patterns

Gravatar Billy, I was going to comment on your example on Code Project along the lines of what you are discussing here. I enjoyed your article lots and it gave me some ideas.
One thing I noticed, however, was the dependency of your presenters on your DAO pulling in your domain objects directly. I use a Service layer on top of my domain and allow my Presenters to only access my domain via that layer, kind of like the example from jeremy you have linked in your other writings on MVP. This dependency may not be a big deal in smaller apps or for consumers of domains that aren't very complex, but having data access in the presenter layer seems to muddy the presenter's roles. It seems like having a service interface your presenter/controller/whatever is interacting with will allow changing the view strategies (like from superivising controller to passive view).
Finally, I himmed and hawwed (Oklahoma expression) about whether to use DTO's or not and eventually decided to use them despite the Hibernate in Action's suggestion against them. I know they are a kind of anti-pattern and they are a bit of a hassle but provide a clean way to standardize messages from the domain/service layer and protect my domain from client abuses.
I'm newer to MVP than you are but thought I'd throw my two pennies in. 7/20/2006 8:33 AM | Mike

# re: Model-View-Presenter split into two "new" patterns

Gravatar Thanks for the comments Mike. Your service layer suggestion sounds interesting. Do you know of other resources, besides Jeremy's, that may explain this approach a bit more?

Thanks,
Billy 7/20/2006 8:43 AM | Billy

# re: Model-View-Presenter split into two "new" patterns

Gravatar Fowler's PoEAA book has a detail on p133, "Service Layer". Also, check out Session Facade in Java writeups (like Sun). Larman talks about it in his Applying UML and Patterns book as well. Basically, it's an interface that provides the contract for interactions with your domain and allows the indirection to keep the clients totally independent of the domain. I implement these as Singletons but you can DI these objects as well for greater flexibility and testability.
All clients consume your domain through this THIN layer. THere shouldn't be business rules in this layer (usually) although it looks like some folks put application rules here (as opposed to DOMAIN logic). When you abstract all this away from consuming your domain directly, you can move the parts of your app around alot easier.
For example, I had a complex server control that I wanted to use but I had totally refactored the domain that the control interacted with and changed the way items are updated and so on. Since I am joining my presenter to the IService interface and since my DTO's shield the complexity of the domain objects I was able to update my control within just a little time. Hope this helps. 7/20/2006 9:13 AM | Mike

# re: Model-View-Presenter split into two "new" patterns

Gravatar Thanks for the extra info Mike...I'm looking forward to trying this out.

Billy 7/20/2006 11:07 AM | Billy

# re: Model-View-Presenter split into two "new" patterns

Gravatar Man, just when you think you have it nailed. I'm really groking the MVP thing and finally got it. The big issue for me was the fact that I had a strong coupling between the Presnter and my Model, however as mentioned you can use a service layer (maybe with dependency injection?) so as to separate it.

I'm just trying to see what Fowler's getting at with his Passive and Supervising Controller, but I still think there are easier variations on MVP. You mention the controller makes MVP easier, but I disagree and the fact that it has a direct reference to System.Web means I have to have different controllers for different interfaces. Not a good plan in my books. With current implementations of MVP, my Presenter (Controller) and View know nothing of user widgets which makes testing and portability easy for me.

But maybe that's me. Need to do more research and testing to figure it all out. 7/24/2006 10:31 AM | Bil Simser

# re: Model-View-Presenter split into two "new" patterns

Gravatar I agree about the System.Web reference...I *really* don't like my presenters/controllers knowing anything about System.Web...really! ;) Honestly, I don't see much difference between the previous MVP definition and Supervising Controller...so I'll just rename the layer MyProject.Presenters to MyProject.Controllers and I think I should be up to date with the latest Fowlerology.

Billy 7/24/2006 11:18 AM | Billy

# re: Model-View-Presenter split into two "new" patterns

Gravatar Hi Billy, thot you might want to see this article...he is implementing a service layer and DTO's. I arrived at a similar framework and have found it to work great!
http://msdn.microsoft.com/msdnmag/issues/06/08/DesignPatterns/default.aspx 7/27/2006 5:22 PM | Mike

# Podcast:: Design Patterns Bootcamp: Model View * Patterns

Gravatar Design Patterns Bootcamp: Model View * Patterns Listen to the Show! Thanks to Dave Bost for the intro! 3/8/2007 10:16 AM | Polymorphic Podcast

# Podcast:: Design Patterns Bootcamp: Model View * Patterns

Gravatar Design Patterns Bootcamp: Model View * Patterns
Listen to the Show!

Thanks to Dave Bost for the intro!... 3/8/2007 10:18 AM | Craig Shoemaker

# re: Model-View-Presenter split into two "new" patterns

Gravatar HI, You can read more about the MVP split in
http://aviadezra.blogspot.com/2007/07/twisting-mvp-triad-say-hello-to-mvpc.html 9/18/2007 5:27 PM | Ori

# re: Model-View-Presenter split into two "new" patterns

Gravatar Hi,

Nice post! Regarding MVC/MVP patterns you might be interested in a Model View Presenter framework implementation for .NET - MVC# ( http://www.mvcsharp.org ).

Regards,
--
Oleg Zhukov 10/30/2008 8:11 AM | Oleg Zhukov

# re: Model-View-Presenter split into two "new" patterns

Gravatar
For those of you out there who don't already know, Cave is porting their gothic arcade shooter DeathSmiles to the Xbox 360 in Japan. The game represents only the second horizontal shooter from Cave and is unlike anything else they've developed before. wow goldThe spooky theme of the game, not to mention the manic game play, gives the game a very unique look and feel to it. Considering the arcade PCB still retails for in excess of $2500, it's a safe bet that shooter fans are quite happy that Cave is bringing the game over to the Xbox 360 console. wow goldThe game is set for release in Japan sometime during Spring 2009. It's nice to see Cave still taking the time and spending the money to bring their amazing shooters to the home consoles. Let's hope this streak continues. I'll have impressions of the game as soon as it's released in Japan
1/18/2009 6:33 PM | cqx

# re: Model-View-Presenter split into two "new" patterns

Gravatar Cool,
google
2/3/2009 9:28 PM | Mike

# re: Model-View-Presenter split into two "new" patterns

Gravatar they've developed before. wow goldThe spooky theme of the game, not to mention the manic game play, gives the game a very unique look and feel to it. Considering the arcade PCB still retails for in excess of $2500, it's a safe bet that shooter fans are quite happy 4/30/2009 2:27 AM | Lingerie

# re: Model-View-Presenter split into two "new" patterns

Gravatar I really like your post, thanks for sharing. 5/30/2009 4:09 AM | flyff penya

# re: Model-View-Presenter split into two "new" patterns

Gravatar What do you know World of Kung fu Gold. 6/1/2009 3:44 AM | World of Kung fu Gold

# re: Model-View-Presenter split into two "new" patterns

Gravatar Do you want to know the magic of online games, and here you can get more Sho Online Mun. 6/14/2009 10:38 PM | Sho Online Mun

# re: Model-View-Presenter split into two "new" patterns

Gravatar As a new player , you may need some game guides or information to enhance yourself.
knight gold is one of the hardest theme for every class at the beginning . 6/15/2009 3:05 AM | knight gold

# re: Model-View-Presenter split into two "new" patterns

Gravatar I am so happy to get some ro zeny 6/21/2009 10:06 PM | ro zeny

# re: Model-View-Presenter split into two "new" patterns

Gravatar It is the LOTRO Gold which make me very happy 6/28/2009 9:34 PM | LOTRO G

# re: Model-View-Presenter split into two "new" patterns

Gravatar I have played this MIR2 game for many years old and now my big feeling is that if you wan to play online game you must have much money to buy MIR2 gold first, 7/21/2009 11:10 PM | buy MIR2 gold

# re: Model-View-Presenter split into two "new" patterns

Gravatar I'm very happy to play it. 8/16/2009 4:34 AM | Lingerie Girl

# replica rolex GMT

Gravatar Vår website erbjuder också mest olik, och stilfullt spänna av kopian replica Omega för våra tittare. 9/10/2009 5:19 AM | Nicole Thompsen

# Rolex replica

Gravatar Det �r n�dv�ndigt att du s�ker efter en produkt som skulle passar dig som var b�st, n�r den kommer till tooth whitener av dina t�nder. 9/21/2009 12:07 AM | Nicole Thompsen

# re: Model-View-Presenter split into two "new" patterns

Gravatar to find best super bright led 9/29/2009 12:21 PM | super bright led

# re: Model-View-Presenter split into two "new" patterns

Gravatar Jeżeli ty chcieć the i unikalny model Replika fake rolex Submariner Daytona zegarek wtedy ty musieć nasz strona internetowa.
10/1/2009 4:53 AM | Matthews

# re: Model-View-Presenter split into two "new" patterns

Gravatar Thank you so much for this outreach! Someone on Yahoo Answers referred me here and now I will be referring everyone I know!

10/13/2009 8:07 AM | sexy lingerie

# re: Model-View-Presenter split into two "new" patterns

Gravatar I on the vision, within the scope of all have become dim. metin2 yang 10/26/2009 1:17 AM | tt

# re: Model-View-Presenter split into two "new" patterns

Gravatar I slowly will be closed files, trying to break out from those words, but seems to have the invisible power will I on the vision, within the scope of all have become dim. metin2 yanga brilliant light anomalies 10/27/2009 11:00 PM | metin2 yang

# re: Model-View-Presenter split into two "new" patterns

Gravatar It is possible to have a Passive View, where the view has no knowledge of the model and also have a presenter with no dependency on System.Web. This is accomplished by each view have an Interface specification, mainly necessary for the mock view, and by creating setters and getters for properties in the view that are managed or used by the presenter. All postback actions in the view raise events that are handled by the presenter. There is no logic in the view, it is all in the presenter or service layer (which interfaces to the model).

The final advantage of the Passive view implemented in this manner is that the interface definition and the the view setters and getters can all be created automatically by a code creation utility that took less than a day to create. 10/30/2009 8:47 PM | John Davidson

# re: Model-View-Presenter split into two "new" patterns

Gravatar Thanks for the input John. I do believe you're right; but that's also one of the problems that I feel is inherent with MVP...the lines between the layers aren't very thick. Compare this to MVC which I feel is much more contained in their discrete layers. Because of this, I moved to MVC a couple years ago and have been very satisfied with the move. 11/6/2009 5:14 PM | Billy McCafferty

# re: Model-View-Presenter split into two "new" patterns

Gravatar Really interesting ! 11/24/2009 8:50 AM | pari sportif

# re: Model-View-Presenter split into two "new" patterns

Gravatar Late at night.metin2 yang A dream. metin2 yang 12/4/2009 8:15 PM | aion kinah

# Hey!

Gravatar Nice to meet you!!!
dinela restaurantweek 12/9/2009 6:17 PM | SoundJohn

# re: Model-View-Presenter split into two "new" patterns

Gravatar Considering the arcade PCB still retails for in excess of $2500, it's a safe bet that shooter fans are quite happy 1/9/2010 11:57 PM | handbags

# re: Model-View-Presenter split into two "new" patterns

Gravatar The articles close to this good post are published by the essay writing service thus, I are willing to buy an essay or written essay about it. 1/17/2010 7:03 AM | KristaSZ26

# its look like lot of extra work..

Gravatar At first glance, implementing MVP looks like a lot of extra work. In fact, it will slow development a bit during the initial stages of development. http://www.datelot.com 2/5/2010 1:11 PM | Travel Guide

Post a comment





 

 

 

Copyright © Billy McCafferty