• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Model-View-Presenter - help

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I recently read about Model-View-Presenter on Martin Fowler's website, and elsewhere. I think I understand the idea...

The view just displays the GUI components..events fired from the View are delegated to a Presenter. The presenter then deals with the model and updates the View accordingly. Sound about right?

Ok, so I learn best by example..and I haven't found any code samples yet, so I thought I'd give it a shot. Below is my code...

Model


View


Presenter


and here is a simple Main to tie it togehter.


Ok, the idea is this. The GUI shows a checkbox and a textfield. basically, if the checkbox is selected the textfield is enabled and can be typed into. If the checkbox is not selected, the textfield is disabled. From the model point of view, if isClassical is false, then no composer can be defined.

So, is my code following the pattern? Does anyone have any simple code to contribute as an example? For some reason is just seems weird to me that I would have an interface define a bunch of methods that the Presenter can call. And I have to create the Model and View which get passed to the presenter, and then I have to set the presenter on the view....it just seems weird to me.

Any comments, suggestions, examples??

Thanks for your time and contributions.
Craig
 
craig wickesser
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anyone?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some comments:

- your presenter doesn't update the Album yet.

- ideally your presenter isn't dependend on AWT/Swing at all (you have to use your own events for that). That would allow you to have, for example, an SWT view, without having to duplicate the presentation logic.

- in some cases you might also want to have the presenter listen on the model (Album) for changes, so that it can update the view should someone else change the model.

- think about what it takes to unit test the presentation logic. With MVP, you just need to test the presenter, the test just needs to send it some events and observe that it reacts accordingly. Without MVP, the test needed to operate a Swing GUI, which is a much more complex task. Google for "humble dialog" for more examples on this topic.

Hope this helps...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic