Datasheet

In the above application, all the application’s functionality is mixed together: data modeling, data
collection, and logical scripting. Although the application might work, making changes without
introducing bugs will be difficult, especially for a multi-developer team trying to work together on
the application without constantly disrupting each other’s work.
A modular application such as the version in Listing 1.2 breaks up functionality into modules that
each handle one part of the application’s requirements. This architecture is easier to maintain
because the programmer knows immediately which module requires changes for any particular
feature.
LISTING 1.2
A modular Flex application
<?xml version=”1.0” encoding=”utf-8”?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:Script source=”scriptFunctions.as”/>
<valueObjects:AValueObject id=”vo”/>
<views:ADataGrid id=”grid”/>
<forms:AForm id=”form”/>
</mx:Application>
Flex implements modularity through the use of MXML components and ActionScript classes that
together implement the bulk of an application’s functionality.
Encapsulation
Encapsulation means that a software object should hide as much of its internal implementation
from the rest of the application as possible, and should expose its functionality only through pub-
licly documented “members” of the object. A class definition that’s properly encapsulated exposes
and documents these object members to allow the application to set properties, call methods, han-
dle events, and refer to constants. The documentation of the object members is known as the
application programming interface (API) of the class.
In the Flex class library, class members include:
Properties: Data stored within the object
Methods: Functions you can call to execute certain actions of the object
Events: Messages the object can send to the rest of the application to share information
about the user’s actions and/or data it wants to share
Constants: Properties whose values never change
In Flex, encapsulation is fully implemented in ActionScript 3. Each member that you define in a
class can be marked using an access modifier to indicate whether the particular method or prop-
erty is
public, private, protected, or internal. A public method, for example, allows
11
About Flex 3
1
06_287644-ch01.qxp 6/23/08 11:28 PM Page 11