Flash_and_Flex_03_2009

Flex Application Architecture

be accessing such as HTTP, Web Services, Flash Remoting, etc. Placing all of your services in one central area will be very manageable and extendable for the future. The Service Delegate is responsible for calling the actual server side methods on the server. It accesses those services by using the ServiceLocator to locate the server, and itself to actually invoke those methods. The Front Controlle r is responsible for capturing Cairngorm Events that are dispatched throughout the application, such as clicking of a button, initializing of a component, response from user interaction, etc. The FrontController then maps the captured event to the proper Command. The Command is responsible processing the event by running the Command class execute() method, thismethod is an ICommand interface method, which the Command implements. The Command is also responsible for updating

the ModelLocator, as well as invoking a server side service with the help of a Delegate. The Value Objec t represents an entity of something, the Value Object is nothing more than a representation of an item, or data structure, it just holds the attributes of data in which you are representing. The View , the view of your application in which will be presented to the user for interaction, the view is responsible for dispatching user or system-generated events. It also binds to the ModelLocator for data representation.

• Commands carry out the event, by updating the ModelLocator and/or calling services defined inside the Delegate • Views dispatch application wide events • Views watch data stored inside the ModelLocator • Views are visual components (buttons, panels, data grids, etc.) • Views can contain child views and components • Even and is a view • Allows designers, developers and data- service developers to work together • Best used for medium to large sized applications • Great in team environments • Provides also easier maintenance, easier debugging, feature changes, and enhancements Cairngorm in Depth ------------------------------------- Value Objects When developing Flex applications it is best to create classes that represent the objects being represented or accessed through out your application, if you were displaying pictures from a art gallery, you would create a class named PhotoVO.as with public variables that represent the attributes of that photo such as height, width, filename, etc. Value Objects are used to create a layer of data objects that can be transferred between components and server side tiers, instead of generic objects, arrays, etc. When you use Value Objects to represent data you are allowing a stricter typing on the client, this is really great when working in Flex Builder because any references to properties inside of that value object that do not exist, or types that do not correspond with one another, the compiler will throw a error, letting the developer know exactly where the problem lies. You are setting a standard for the specific entity you are representing. Benefits of using Cairngorm • Attributes represent that entity • Same layer as the ModelLocator • Create ContactVO.as , see (Listing 1). • Discuss – Value Object The ContactVO.as value object holds all of the attributes for a contact inside of this application. This exact data is expected to come back from the server side service that this object is representing. • Identify ValueObject : • Entity of something • Strong typed objects

Overview

• ModelLocator holds data • Service Locator holds service locations • Delegate holds service methods • FrontController captures events and maps to proper Commands

Listing 1. ContactVO.as

package com.jonniespratley.flexcontacts.vo {

import com.adobe.cairngorm.vo.IValueObject;

[RemoteClass(alias="com.jonniespratley.flexcontacts.vo.ContactVO")]

[Bindable] public class ContactVO implements IValueObject { public var contact_id:int;

public var contact_fname:String; public var contact_lname:String; public var contact_email:String; public var contact_url:String; public var contact_address:String; public var contact_address2:String; public var contact_state:String;

public var contact_city:String; public var contact_zip:String; public function ContactVO( obj:Object = null ) { if ( obj != null ) { this .id = obj["id"]; this .name = obj["name"]; this .address = obj["address"];

this .city = obj["city"]; this .state = obj["state"]; this .country = obj["country"]; this .email = obj["email"]; this .phone = obj["phone"]; this .zip = obj["zip"]; this .date = obj["date"];

}

}

}

}

03/2009 (5)

53

Made with FlippingBook HTML5