MVC Structure - Need a little help.
Hi Guys,
I need some help with how to structure a major application in MVC, basically I have several applications (a gallery app, a coverflow app and a dataGrid application) that I want to display inside an main application.
The main application has a menu to select each application to load, and each loaded application is a Composite View containing other views like image display views, scrollbar views, sliders etc.
I am using the MVC pattern and the Composite pattern to create the applications themselves and simplify the update process, and I have a few questions about structure:
1. At present I am creating each view (i.e. galleryView, CoverflowView, dataGridView) and each Model for each view in the Main (document class), and to each model I am passing an different XML file for that application from the document class. Is this the right way to do it? or is there a better way? Also, should eventListeners to the model, do inside the document class, or the views themselves?
2. Also, is it normal to create views inside other views? In other words, say I have a galleryView that is a Composite Object. Should I be creating and adding new views (i.e. scrollBarView, imageView) to the galleryView - inside the galleryView class, or is it better to create other views outside the galleryView class and then add() them to it as part of its composite structure (as below), for updating?
var galleryView:Composite = new galleryView(model, controller);
var scrollview:Composite = new ScrollView(model, controller)
galleryView.add(scrollView).
3. One other thing I am having trouble with is how to change between views. In other words if I have a navigation that changes between the galleryView and the DataGridView, would I have to remove all the (component) views inside the galleryView first, and then create the DataGridView, or is it better to simply hide the galleryView and un-hide the DataGridView, and vice versa?
Any help on this would be greatly appreciated, as I have been on it for days...
Tom.
Sent you an invite on Gmail.
Hi Marlopax,
Thanks again for all your time.
I've been on this again today thinking about different ways I could create an interface for the different apps.
From what I understand after all we've talked about, is that the document class should contain all the app views (coverflowView, galleryView, mapView etc). And each app view should have its own model and controller and xml file.
The document class will also contain a Nav view (seperate from the app views in the document class). Ultimately though, the Nav view will be responsible for changing between app views.
Looking at it this way, all the views (each app, and the navigation) are independent and responsible for their own functionality and sub views.
.....I feel I am nearly there. However, I am still stuck on how to tie this all together in the document class - i.e. how to tie events from the Nav View to the creation/removal of app views in the document class. Is there an easy OOP way to do this?
I mentioned placing a method in the document class to create/remove the views according to events from the Navigation, but as you said "
case will not make your architecture flexible.".
You also mentioned that the Navigation View IS the Controller, and that all I need to do is load the XML for the navigation, and that the other XML files for each app would load according to the users need, but I don't quite understand this? Could you be more specific about how the Nav View could control the loading of the different XML files and creation of other views?
Also, if I do create all the views as well as their models and controllers in the document class, they will all compose at the same time and overlay each other unless given some kind of condition tied to the navigation view.
In basic terms, what I want is the following:
1. Document class loads up and displays app 1 and provides a navigation view for changing to other apps.
2. user changes the app shown from the current app view in the document class. Document class removes current app view in the document class and tells the new view to build based on the navigation button pressed in the Nav View - cycle repeats.
Should I be including this logic to change between views in the document class? Should I be encasing all the app views inside another view that listens to the document and handles changing between views? Should each app view itself contain the logic to build or remove it using some kind of init() function?
... I think i'm going crazy over this.
:(