Hi All,
I'm about half way through the OU M206 course and enjoying every second.................. This has nothing to do with that, it was just a pointer (C++ bah! humbug!) to my level of ability with ST. I have been reading this group, the archive (thanks to Ian) and the examples provided with Dolphin Pro and have finally managed to make a little sense of MVP but............. My model, a Shipwreck class, has several instance variables holding (such as) the name of a ship, its gross tonnage, depth etc. I have managed after lots of frustrating effort to get an initialized instance of Shipwreck to appear in a ShipwreckShell presenter and to add: itself to a Class/Instance variable (Wreck) which holds a ListModel to collect the Shipwrecks entered by means of Prompters. This is fired by pressing a button to create the new instance and the add itself to the Collection held by Wreck. The Problem. Although the above seems to work fine is it a good way of achieving this, and more importantly, how do I interate through the collection held by Wreck and display it in the presenter? Also the presenter only ever seems to show the initial instance created on startup of the Shell. How do I perform an update. I realize this has something to do with triggers but what.............how............ Please give me some pointers (it took me a long time to understand these too!) before I end up as a Yul Bryner lookalike. Thanks for your time and patience with a beginner, Cheers, Roy |
Roy,
Welcome. > My model, a Shipwreck class, has several instance variables holding (such > as) the name of a ship, its gross tonnage, depth etc. > I have managed after lots of frustrating effort to get an initialized > instance of Shipwreck to appear in a ShipwreckShell presenter and to add: > itself to a Class/Instance variable (Wreck) which holds a ListModel to > collect the Shipwrecks entered by means of Prompters. This is fired by > pressing a button to create the new instance and the add itself to the > Collection held by Wreck. First of all I think you might be having problems because your example above is a bit too simple (_not_ a criticism, just an observation!) for an MVP example. The MVP overhead, when applied to something that is basically a Shell displaying a Collection, may be going to obscure more that it illustrates. Have a look at the attached "Shipwreck1" which just uses two classes - Shipwreck - just containing the date for one Shipwreck and a display method, nothing else. - ShipwreckShell1. The main Shell which has an instance variable "shipwrecks" containing a collection of your defined Shipwrecks (instances of the Shipwreck class) and the, minimal, logic to maintain this collection. The Shell class also contains the code to interface to the other three MVP triads involved (the three display widgets). Note that this shell presenter has no explicit model! I've added a few comments in the code which may help to see how it fits together. Changing it into an application that does use a shell MVP triad will involve moving the "collection" aspect (the shipwrecks instance variable in the above) out of the Shell and into a Model - NB. this Model will not contain any individual Shipwreck data, just a collection of Shipwreck instances. We should now have -ShipwreckShell2 - A Shell subclass and your top level presenter. Has a ListView showing all the entered shipwrecks and one button, "add" that sends #addWreck It asks it's Model (a Shipwrecks instance) to inform it when the collection of shipwrecks changes. -Shipwrecks - A Model subclass that acts as ShipwreckShell2's model. This contains a private collection that holds a list of shipwrecks. All access to this collection is via messages, usually from ShipwreckShell. -Shipwreck - As above except that it now has a method to get the information about the shipwreck it represents from the user. So how does it work together? -ShipwreckShell2 show Opens up and displays the shell. Also initialises a default (empty) model. File save/load will come later <g>. When the shell is ready (#onViewOpened) it asks the model for a list (initially empty in this case) of shipwrecks and displays them in a list view -User presses "add" The shell just informs the model that it needs to obtain and add a new Shipwreck. Normally the shell or model would do this using a dialog but here we will ask the Shipwreck to get the information itself. The model adds the new shipwreck to the collection and fires a trigger event, #shipwrecksUpdated. The shell, which has previously registered an interest in this event with the model, responds to the event by getting an updated list from the model and displaying it. -User selects a item in the list As the list contains instances of Shipwreck (not Strings but the actual instances) we can just interrogate the selected item for the list for the information. _If_ we did just have Strings in the displayed list we would have to ask the model for the Shipwreck appertaining to the selected String. Final point. This may well not be the way I would do it "in real life" (tm) but, hopefully, it shows the separation of some of the responsibilities -Shipwrecks (a Model) maintains a collection of shipwrecks and looks after any additions (or other changes) and notifies interested parties when anything occurs. -Shipwreck (a Data wrapper class) just maintains the information for a single shipwreck and, in this case, how to obtain information from the user. -ShipwreckShell (the Presenter) knows about Shipwrecks and Shipwreck instances and how to obtain information from them. Is the connection point for all the other MVP triads. > Thanks for your time and patience with a beginner, We've all been there <g> You might also like to check the archive for a thread that started just before Christmas last year (and never resurfaced after the break) which went through another MVP example - a Library. It started on 20/12/200 in a thread entitled "Specific MVP troubles (long)" Ian begin 666 Shipwrecks.zip M4$L#!!0````(`-U5V"K8X@'MY1 ```1@```.````4VAI<'=R96-K<RYP86/M M6FUSVS82_IS,Y#_0Z@<Y-U7*=TKNW,U(E)3VIDD\=9I^N+G.T!(ML:9)E:3L MN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