A question was posted to the 615Flex message board today that distilled to: “When and why should I use Flex Modules instead of just creating a Flex Component?” Ben recommended I post my reply here:
First - What are Flex Modules?
Modlues are pieces of an application that compile into their own .swf files and are loaded, as needed, at runtime. Please read more here:
http://livedocs.adobe.com/flex/3/html/help.html?content=modular_1.html
When should Modules be used?
- When the application has multiple complete chuncks of functionality.
- When it is desirable to only load those chunks if/when the user needs them.
- When chunks of the application should not be delivered to clients without permission (i.e. an Admin module)
Why should Modules be used?
- To reduce the load time of an application. Modules load as needed while compiled-in components increase the size of the containing .swf.
- To improve performance and client side footprint. Modules can be unloaded when not needed or not being viewed.
- To deliver incremental changes to a piece of an application (a Module) without deploying the entire app.
- To potentially share a chunk of functionality across multiple applications. (i.e. you may want to use the same Contact Manager module across two CRM applications.) As nice as this sounds, it can make versioning, change management, QA and development a nightmare as requirements change in one deployment and not the other.
Here are four examples that have been useful to me. Maybe it will help you decide when to use Modules in your application.
- MXML Modules:
When someone says “Flex Modules” this is likely what they are referring to. The .swf that is generated is usually a visual component and is typically loaded with the ModuleLoader MXML tag.
http://livedocs.adobe.com/flex/3/html/help.html?content=modular_3.html - AS Modules:
ActionScript based modules are AS classes that extend ModuleBase and are compiled into .swf files. These modules are generally non-visual components. A possible use would be to load an implementation of an AS interface into the application based on a user role.
(bottom)http://livedocs.adobe.com/flex/3/html/help.html?content=modular_3.html - Reusable Modules across Applications:
Proceed at your own risk. Modules can be compiled to be optimized for use in a specific Application, however, you may disable this feature and create a reusable Module for use across Applications.
http://livedocs.adobe.com/flex/3/html/help.html?content=modular_4.html#191026 - Slightly off topic: Sub Applications vs Modules
Flex applications can load other Flex applications as children in a similar way to how Modules are loaded. If this interests you, please read this PDF very carefully:
http://livedocs.adobe.com/flex/3/loading_applications.pdf.
If you had the same question that sparked this post, hopefully this has shed some light and pointed you towards more useful resources. I’m happy to answer any questions about Modular application architecture as well as Sub Application architectures.