[Arp] Maintainig object state
Nils Millahn
nils.millahn at deltabravo.com
Fri Apr 22 03:32:41 PDT 2005
Hi Christophe,
similarly to Aral's suggestion - introduce a Model class (singleton)
that is accessed by the Commands only - so the views would still request
data via the normal controller/command interaction. The Command then
goes to fetch the data from the Model and returns it to the view.
The first time round, the Model would be unpopulated, so you'd need to
load/parse the data from your XML file. From then on, you can get it
from the Model straight away.
Thsi way the views don't need to know whether the data is coming from an
XML file or directly from the model + you don't use views to store the
actual data, only to display it.
- Nils.
Christophe Herreman wrote:
> Hi all,
>
> We're currently developing some e-learning apps. They are all fed by XML
> (using the XMLService which works fine, so far). They are then parsed to
> objects of the type Course, Chapter, Assessment, AssessmentItem. Courses
> contain Chapters, Chapters contain Assessment, etc.
>
> The thing is that this XML data only needs to be loaded once in the
> application (in reality not once, but just for this example). This is
> important because we want to keep scores in the AsessmentItem objects for
> instance. We also want to know what Chapters have been looked at by the
> user.
>
> The question is: Where do we save e.g. the Course object?
>
> We made a subclass of ArpForm, IdiomaticForm which has a getModel and
> setModel method. This seems like a good approach because when the app
> starts, the Application form (extends IdiomaticForm and which is actually
> the view of the Course model) broadcasts a getCourse event. The
> controller
> maps it to a GetCourseCommand. That command calls the getCourse method on
> the XMLService. The course gets loaded and parsed. When it is parsed, we
> call viewRef.setModel(resultEvent.result). So the Application receives
> the
> course object. Is this a good thing to do?
>
> Another problem we have is that when we enter a Chapter, we want the
> ChapterForm to get the chapter data. This shouldn't be loaded, because
> it is
> already in the course model of the application. But how do we access
> it from
> within the ChapterForm? Do we send an event (type:"getChapter",
> chapterID:3)
> which Application listens for and then does something like:
>
> function getChapter(eventObj){
> chapterForm.showChapter(getModel().getChapterAt(chapterID));
> }
>
> I don't know if this is a good thing because Application now knows
> about the
> showChapter method of ChapterForm.
>
> Maybe a better way is to send that event to the controller. The
> controller
> executes a getChapter command. That command reads the applications model
> (how does he access it? viewRef._parent?) and the does
> viewRef.setModel(chapter).
>
> All the apps are offline CD-ROM apps.
>
> Any advice, tips or tricks?
>
> thx a million,
> Christophe
>
> _______________________________________________
> Arp mailing list
> Arp at ariaware.com
> http://ariaware.com/mailman/listinfo/arp_ariaware.com
>
>
More information about the Arp
mailing list