[grand-rapids-pm-list] Fwd: Model View Presenter

Jason Porritt jasonmtu at yahoo.com
Thu Jul 12 10:59:10 PDT 2007


That is a good question, but one I haven't worked through myself :)

I'll offer my thoughts anyway, and I think you're right that the Model should, in some way, own the transaction management.  Here are two ideas that I think would keep things in line with the goals of Presenter First.

Manage transactions in the Presenter through the Model.
Create methods on the Model that wrap your database transaction functions like (in perl) begin_work, commit, and rollback with more end-user oriented names like start_changes, save_changes, and abort_changes.  Call those methods from the Presenter like:

$model->start_changes();
$model->abort_changes() unless $model->save_new_username($username);
$model->abort_changes() unless $model->save_new_address($address);
$model->save_changes();

I know this is a trivial exmple, but I think that sort of logic does still sound reasonably like the story of the application from the user's perspective.

Include all elements of a transaction in a single method.
In other words, don't spread transactions across multiple Model methods :)  I think I would prefer to keep the Presenter in the dark about transactions and let the Model handle it.  This also goes along with the "Finish what you start" idea from Dave Thomas' book The Pragmatic Programmer, which I've found to be good advice.  (I am willing to accept that there may be situations where this doesn't make sense)

Conclusion
As I said, I haven't worked through this myself so these are just unproven, untested ideas.  This might be a good discussion to carry over to the XP West MI mailing list.

Hope that helps,
Jason Porritt


----- Original Message ----
From: Carlus Henry <carlushenry at sagetech-llc.com>
To: grand-rapids-pm-list at pm.org
Sent: Thursday, July 12, 2007 10:06:51 AM
Subject: [grand-rapids-pm-list] Fwd:  Model View Presenter

Meant to send this message to everyone.....What do you guys think?

Carlus

---------- Forwarded message ----------
From: Carlus Henry <
carlushenry at sagetech-llc.com>
Date: Jul 12, 2007 10:06 AM
Subject: Re: [grand-rapids-pm-list] Model View Presenter
To: Jason Porritt <jasonmtu at yahoo.com>


Hey bud....

In your work with MVP, does when the presenter delegates to the model, who owns the transactions when doing commits?  I am thinking that the model should own the commits....but what happens if the work that needs to be done is happening across two seperate model calls.  When the second model operation fails it should roll back the first.  But you are not able to do this unless the transaction is being controlled at the presenter level, which just feels awkward.


What have you done?

Thanks
Carlus

On 7/11/07, Jason Porritt <
jasonmtu at yahoo.com> wrote:


Thanks for the follow-up, Carlus.  Atomic Object's Presenter First pattern is indeed very interesting, and I kind of wish we had jumped into that during the MVP discussion but we probably would have run out of time for the Perl testing section.  Here are a few other links related to the meeting I meant to share with the group at the end:


UI Design Patterns (Martin Fowler)
    GUI Architectures

    Inversion of Control Containers and the Dependency Injection pattern



Perl
 Testing
    Test::More
    

Test::MockObject

And to answer one of Carlus' other questions about IoC (Inversion of Control) containers for perl I did find two that look interesting:
    

IOC
    Peco::Container

My initial impression is that Peco::Container is a bit simpler than IOC.  I haven't used either of them yet so I don't have much but the documentation to base that on.  Neither of them do anything other than IoC, so a fair comparison may be between these two and Java's 
PicoContainer instead of Spring which
 is a full application framework in addition to an IoC container.

Thanks,
Jason Porritt


----- Original Message ----
From: Carlus Henry <carlushenry at sagetech-llc.com>
To: 

grand-rapids-pm-list at pm.org
Sent: Thursday, July 5, 2007 8:48:30 AM
Subject: [grand-rapids-pm-list] Model View Presenter

For those of you that did not come to the last Perl User Group meeting, you missed a great presentation which prompted a wonderful discussion on the Model-View-Presenter Pattern (MVP).  Primarily being a J2EE developer and with many years of experience with the Struts Framework, I am very familiar with the Model-View-Controller (MVC).  I was very interested, however, in this MVP pattern.  This is mostly due to the thick client application development that I have been doing lately.


During the meeting, a lot of questions were raised regarding this pattern, and Jason Porrit was very patient with all of us (touche').  After the meeting, I decided to do a little more investigation, and found the following:


Martin Fowler Retires Model View Presenter Pattern

Yes.  Believe it or not, this 


pattern has been retired
 by Martin Fowler.  Well, I don't know if retired is the correct 'r'-word.  Maybe it should say 'R'efactored instead.  He has split up the pattern into the 



Supervising Controller and the Passive View.  After reading both of the patterns, they sound very similar in detail and in practice.  In the Passive View you put all of the widget population logic into the Presenter.  All logic is pushed on the Presenter including the population of text fields or any other widgets available on the View.  In the Supervising Controller, you push most of the logic onto the Presenter, but leave some of the logic of populating widgets in the View.  Martin states:


"...the essence of a good Supervising Controller is to do as
		little as possible. Let the view handle as much as possible and
		only step in when there's more complex logic involved."

Atomic Object Presenter First
On a related note, 


Atomic Object also has their own variation of the MVP Design pattern called Presenter First (PF).  After reading an article from Better Software magazine (referenced from their 


PF resources), I find this design pattern very attractive as well.  What most attracts me is the concept of linking different PF triads in order to orchestrate behavior and a process.  Please refer tot he Better Software article for more information on this.


Overall, I owe a big thanks to Jason Porrit for inspiring me to learn more about this design pattern.  I look forward to hearing him present in the future.

-- 
Carlus Henry
SageTech 
L.L.C.

www.sagetech-llc.com | 
http://jdcarlflip.blogspot.com/
_______________________________________________
grand-rapids-pm-list mailing list
grand-rapids-pm-list at pm.org

http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list








      Looking for a deal? 

Find great prices on flights and hotels with Yahoo! FareChase.

_______________________________________________
grand-rapids-pm-list mailing list


grand-rapids-pm-list at pm.org
http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list





-- 
Carlus Henry
SageTech L.L.C.
www.sagetech-llc.com
 | http://jdcarlflip.blogspot.com/




-- 
Carlus Henry
SageTech L.L.C.
www.sagetech-llc.com | http://jdcarlflip.blogspot.com/
_______________________________________________
grand-rapids-pm-list mailing list
grand-rapids-pm-list at pm.org
http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list






       
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/grand-rapids-pm-list/attachments/20070712/acaf11a5/attachment.html 


More information about the grand-rapids-pm-list mailing list