I’m rolling out a large project, and I wanted to utilize dynamic modules for scalability.
For those who aren’t familiar will modules, basically, there a great way to encapsulate “pieces” of your application. A trivial example would be a small ‘shell application’ that once the user logs in, loaded the appropriate use-case module. If your working in a team environment modules make for an easy project divide-and-conquer approach.
I’ve been using the PureMVC framework lately and figured adding support for dynamic modules wouldn’t be too difficult as Cliff and the gang have already been hard at working getting the framework changes in place to make this possible (replacing singletons with multitons etc).
Well after some working laying this out, I’m glad to say I’ve got it working. Check out this sample app Dynamic Mortgage Demo.
The demo allows the user to get loan quotes from [fictional] banks. The demo allows the user to dynamically load / unload bank “modules.”
The application and modules are very well encapsulated. Here’s whats required from each party…
Application:
Must compile with…
A reference to any interfaces the modules loaded at runtime implement (ILoadableModule in our case).
A reference to any subclasses of mx:Module the modules are using (PureMVCLoadableModule in our case). This is only necessary if your subclassing mx:Module.
That’s it.
Here’s the integration point on the modules end…
The modules facade implements an “InitializeMapping” function which maps application notification names to local (module) notification names [inbound mapping]. The function also defines module notification name to application notification name [outbound] mappings.
Here’s an example
override public function initializeMappings():void
{
outboundMappings:Array = new Array();
outboundMappings[QUOTE_GENERATED] = EventNames.LOAN_QUOTE_READY;
inboundMappings = new Array();
inboundMappings[EventNames.REQUEST_FOR_LOAN] = QUOTE_REQUESTED;
}
And thats the extent of what our application and modules know of each other. The rest of the ‘work’ is done automatically by a few interfaces / subclasses I wrote on top of PureMVC to make this possible. (i.e. your modules facade subclasses ModuleFacadeBase etc). No framework changes we’re required just some subclassing here and there.