Implementing Composite MVP Components in Javascript



Hi,

I'm building an Address Book application using Javascript/DHTML and am
interested in using the Model View Presenter pattern to enable resuse
of the model classes and to facilitate testing.

Before looking at the pattern I had already implemented much of the
application using components that merged view creation and application
logic so I'm actually trying to decompose the existing code into MVP
triads. I started out looking at the Java example provided by Martin
Fowler in his description of the pattern but this uses an elemental MVP
component only whereas I think I probably need composite components.

If anyone thinks they might be able to help with this a description of
my existing application and the questions it's provoked follow:

In my current object model I have an AddressCardViewer class that uses
DOM methods to create a toolbar and a scrollable viewing pane that
address cards will be displayed within. The AddressCardViewer is
provided with a list of addresses (data objects) as a constructor
parameter. For each address an AddressCard is constructed and laid out
in the scoll panel. The AddressCard class uses DOM methods to create
the cards visual representation and binds event handlers to it for
switching the card into edit mode - where its field values can be
changed.

It looks fairly straightforward to decompose the AddressCardViewer
class into an MVP triad but I've become a little confused in working
out how I should handle the composition of the AddressCards.
Specifically:

- In moving the application logic out of the AddressCard class into a
presenter should there be a one-to-one relationship between an
AddressCard and its presenter or can I have one presenter to handle
actions for all cards, passing a reference to the card when calling the
presenter's methods? Some things that the presenter would need to do
are handle card selection, change the cards appearance when clicked;
re-position the card when it is to be edited.

- Would the AddressCardViewer hold a reference to both the AddressCard
view object and its presenter after it has created them?

- The AddressCard actions, handling card selection and re-positioning
the card require knowledge of the viewer's state. For instance if a
card is already selected, when selecting a new card the previous card
should be de-selected. How should the AddressCard presenter
communicate with the AddressCardViewer presenter? Should it delegate
the action to the viewer's presenter?

- The AddressCardViewer has a list of addresses as its model, when
creating an AddressCard view instance it is initialized from an address
data object. Should I the view be registered as a subscriber to the
data object at this point?

Cheers
Adam

.



Relevant Pages

  • Re: Implementing Composite MVP Components in Javascript
    ... logic so I'm actually trying to decompose the existing code into MVP ... listener and it sits in between the Presenter and View. ... For each address an AddressCard is constructed and laid out ... actions for all cards, passing a reference to the card when calling the ...
    (comp.object)
  • Andrew Card at UMass graduation (video)
    ... until well after he took his sham degree and sat down and his presenter ... I could not find one single graduate without ... Seriously, why would Card ... (with fun video) ...
    (alt.politics.bush)
  • Re: Dual Monitor Support in Power Point for MAC
    ... > Jim is correct that it is the "presenter" view that shows up in the main ... It has never been a problem with the Mac that I've used. ... I've used a Mac with an additional ATi card and it never had any problem ... MVPs are not MS employees - Les MVP ne travaillent pas pour MS ...
    (microsoft.public.mac.office.powerpoint)
  • Powerpoint "Show Presenter View" fails
    ... I'm running XP with Radeon 9700 card and 2 moniters. ... "Show Presenter View" but when I start the presentation, powerpoint crashes. ...
    (microsoft.public.powerpoint)
  • Show Presenter View
    ... I'm running XP with a Radeon 9700 card and multiple monitors. ... "show presenter view" and start the presentation, I get the "Powerpoint has ...
    (microsoft.public.powerpoint)