View Single Post
Nutrox's Avatar Nutrox Nutrox is offline 1 Blog Entries 13 Creative Assets 2007-10-09 #202 Old  
Last edited by Nutrox : 2007-10-09 at 20:53.
After a wee bit of thinking I have decided to let developers choose if they want to implement static constants (for the event types) into the framework. I won't try to enforce static constants into the framework except for BaseModel.EVENT_UPDATE which is the default event type dispatched from Models.

I'm not going to try and do anything fancy with Model/Controller references either, again, developers can always customise the framework if they want to adjust the way certain things work.

By default, Controllers are added to Views, and Views are added to Models. This is essentially the Observer pattern but the pattern isn't enforced using IObserver and IObservable interfaces.

ActionScript Code:
  1. model = ModelLocator.getInstance().getModel( "id" );
  2. view = new View();
  3. controller = new Controller();
  4.  
  5. model.addView( view );
  6. view.addController( controller );
ActionScript Code:
  1. modelA = ModelLocator.getInstance().getModel( "idA" );
  2. modelB = ModelLocator.getInstance().getModel( "idB" );
  3. viewA = new ViewA();
  4. viewB = new ViewB();
  5. viewC = new ViewC();
  6. controllerA = new ControllerA();
  7. controllerB = new ControllerB();
  8.  
  9. modelA.addView( viewA );
  10. modelB.addView( viewB );
  11. modelB.addView( viewC );
  12.  
  13. viewA.addController( controllerA );
  14. viewB.addController( controllerA );
  15. viewC.addController( controllerB );
...and so on.

I will be sticking with the way the Controller registers and executes Commands. The Controller receives an event and executes a Command based on the type of event. In a nutshell, the Controller is dumb, all of the logic required to update Models is contained within Commands. Commands know which Model(s) they need to update (references are obtained via the ModelLocator), and they can call upon Services (using the ServiceLocator) in the usual way.

M » V » C » CMD » [SRV » CMD »] M
 
Reply With Quote