Datasheet

Modularity
Modularity means that an application should be built in small pieces, or modules. For example, an
application that collects data from a user should be broken into modules, each of which has a par-
ticular purpose. The code that presents a data entry form, and the code that processes the data
after it has been collected, should be stored in distinct and separate code modules. This results in
highly maintainable and robust applications, where changes in one module don’t automatically
affect behavior in another module.
The opposite of modularity is monolithic. In monolithic applications such as the example in Listing
1.1, all the code and behavior of an application are defined in a single source-code file. These
applications tend to be highly “brittle,” meaning that changes in one section of the application run
a high risk of breaking functionality in other areas. Such applications are sometimes referred to as
spaghetti code because they tend to have code of very different purposes all wrapped around each
other.
LISTING 1.1
A monolithic Flex application
<?xml version=”1.0” encoding=”utf-8”?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:Model>
...data representation...
</mx:Model>
<mx:Script>
...ActionScript...
</mx:Script>
<mx:HBox>
<mx:DataGrid>
<mx:columns>
<mx:DataGridColumn .../>
<mx:DataGridColumn .../>
<mx:DataGridColumn .../>
</mx:columns>
</mx:DataGrid>
<mx:Form>
<mx:FormItem label=”First Name:”>
<TextInput id=”fnameInput”/>
</mx:FormItem>
<mx:FormItem label=”Last Name:”>
<TextInput id=”lnameInput”/>
</mx:FormItem>
<mx:FormItem label=”Address:”>
<TextInput id=”addressInput”/>
</mx:FormItem>
</mx:Form>
</mx:HBox>
</mx:Application>
10
Flex Fundamentals
Part I
06_287644-ch01.qxp 6/23/08 11:28 PM Page 10