This section is meant as a broad overview of the major components that make up the Cairngorm framework. Subsequent chapters will examine each of these parts in more detail. Because it is an open source project on the Adobe Open Source web site, you have full access to the source code for Cairngorm. The code is stored in a Subversion repository. It is not necessary to check out the source code for the purposes of this book, but if you want to, that option is available to you.

Author:Vozragore Maurg
Language:English (Spanish)
Published (Last):11 April 2014
PDF File Size:7.73 Mb
ePub File Size:3.50 Mb
Price:Free* [*Free Regsitration Required]

The architectural framework Cairngorm was created by Alistair McLeod and Steven Webster while they were working at the company iteration::two they are presently employed by Adobe Consulting. It was open sourced in the summer of Cairngorm was designed to ensure that UI components do not need to know where data is located. The business layer retrieves data from the servers and stores it in the memory objects that represent the data model, which use binding to notify the UI components about data arrival or changes.

On the same note, changes in the UI are propagated to the server side through this business layer. It offers a number of classes implementing Model, View, and Controller tiers, and interaction between them. The Model tier is represented by the class ModelLocator , which stores the application-specific data these are often collections of value objects , a. The View portion contains visual components required by your application, value objects, and Cairngorm-specific event classes used for communication with the Model and Controller tiers.

The Controller tier is responsible for invoking appropriate code containing the business logic of your application, which is implemented by using global FrontController and ServiceLocator classes as well as additional Command and Delegate classes. The List component the View knows about its model and is bound to it directly via its dataProvider property.

When a View component fires an event, FrontController finds the Command class that was registered with this event and calls its method execute. The Command class updates the data in the model typically, a collection of value objects defined in the global ModelLocator. Because each model located inside the ModelLocator is bound to a UI control, its content gets updated automatically.

Please note that the code for the six participants mentioned earlier is organized in separate packages folders. The business folder is for delegates and service components. The command folder is for Command classes; control is for events and FrontController ; the ModelLocator is located in the model folder; and the view folder has visual components as shown in Figures through The value objects of the application have been placed in the folder called vo. Regardless of what framework you are going to use, separating various application components in project subfolders helps make the project more organized.

In the example code, CairngormEventDispatcher dispatches the cgEvent :. To eliminate the need to import CairngormEventDispatcher in every view, starting from Cairngorm 2. On the application startup, the code dispatches LoadEmployeesEvent and, as if by magic, the EmployeeList gets populated from Employees.

How did it happen? This class creates an event with an ID AppController. The next point of interest is the class LoadEmployeesCommand. The method execute must have an argument—the instance of the CairngormEvent object that may or may not encapsulate some application data for example, some value object that is not used in our scenario.

It also implements the interface IResponder , which requires you to add the result and fault methods. By using these callbacks the delegate will return to the command class the result or error information of the execution of the command in question. This leads to the need for additional coding to convert the data to appropriate types. For example, employee startDate will be stored as a string and will require code to convert it to Date if any date manipulations will be needed. Just move the business logic from the delegate right into the execute method of the command class itself.

Create a common ancestor to all your commands and define the fault method there to avoid repeating the same code in each command class. To load the employees, the Command class creates an instance of the proper delegate passing the reference to itself this is how the delegate knows where to return the data and calls the method loadEmployeesService :.

Have you noticed that the Command class has also reached for the AppModelLocator to be able to update the model? For web services, call the method getWebService.

ServiceLocator can be used not only as a repository of all services, but also as an authorization mechanism that restricts access to certain application services based on specified credentials.

See its methods setCredentials and setRemoteCredentials for details. The loadEmployeesService class reads Employees. The Command class updates the model. This model locator stores the data and the state of this application—in particular, the variable employeeListDP , which is the place where the list of employees is being stored.

Please note that as ActionScript 3 does not support private constructors, the public constructor of this class throws an error if someone tries to improperly instantiate it i. For some reason, the author of this code decided not to use EmployeeVO here and stores each Employee attribute separately in SaveEmployeeEvent. The execute method of SaveEmployeeEditsCommand does not use any delegates, as it just needs to add a newly inserted Employee to the model.

Because this application does not save modified data anywhere other than in memory, no other ser vice calls are made to pass the changed data to the server side for persistence. The View portion of the employee list gets updated automatically as a result of data binding. Online, you may encounter lots of debate regarding whether Cairngorm should be used in Flex projects.

We prefer working with frameworks that offer enhanced Flex components rather than just separation of work among team members. If you have to develop a project without experienced Flex developers on your team, however, Cairngorm can give your project a structure that will prevent it from failing.

So, is Cairngorm right for your project? Read Chapters 2 , and 6 , and then decide whether you prefer working with the components described there or one of the architectural MVC frameworks. Meanwhile, keep these observations about Cairngorm in mind:. The problem with this approach is in the global nature of such an event handler. The Front Controller object serves as a central registry of all Cairngorm events.

Although keeping all application events in one place simplifies their maintenance, it leads to tighter coupling of the application components. Using a centralized ModelLocator also makes multiple components dependent on the knowledge of the properties of the model. If your project will start growing, the ModelLocator may not scale well. Modularizing Flex applications is one of the major ways of minimizing the size of the downloadable Shockwave Flash SWF files.

The other benefit is reusability of the modules. Now imagine a midsize web application that consists of 10 modules. If this application has been built using Cairngorm, each of these modules becomes dependent on the central FrontController located in the main. Application developers have to write lots of boilerplate code. For example, you have to create additional event and command classes for every event that can be dispatched in your application.

Even in a midsize application this can translate to a hundred or more additional Cairngorm-specific classes. To minimize the amount of manually written code, consider using Cairngen, an open source code generator for Cairngorm. FrontController allows you to map only one command per event, yet your application may need to have several event listeners per command.

Even though data binding can help in writing less code, because Cairngorm enforces data binding as the only mechanism of updating the views, it makes them nonreusable. Just simply renaming this variable in the ModelLocator will require changes in one or more views that are bound to it. Having no other choice but data binding for updating the UI may cause performance problems. The global ModelLocator object defines multiple bindable variables representing different models, and the Flex compiler may generate additional EventDispatcher objects on the class level this depends on the types of the variables.

Suppose you have 10 [Bindable] String variables in the ModelLocator. If one of them will get updated, not only will its listener get notified to update the view, but the other 9 will get this event, too. The fact that Cairngorm is built around a Command pattern with a centrally located command repository can be very convenient for some projects that require audit or undo functionality.

Cairngorm has been around longer than any other Flex framework. Cairngorm separates business- and UI-related work into different layers, which means that the work of the project team can be split between developers responsible for the visual portion and those who are coding just the business logic of the application.

The fact that all services are located in a central place allows us to quickly reconfigure the data sources, i. Development managers who have to work with distributed teams of beginner or mid-level Flex developers and need a safety net to split the project work into smaller controllable tasks e. It requires developers to write lots of additional classes, which adds to project timeline. Skip to main content. Start your free trial. Command When a View component fires an event, FrontController finds the Command class that was registered with this event and calls its method execute.

ModelLocator The Command class updates the data in the model typically, a collection of value objects defined in the global ModelLocator. View Because each model located inside the ModelLocator is bound to a UI control, its content gets updated automatically. CairngormEventDispatcher; import com.

LoadEmployeesEvent; import com. The class LoadEmployeesEvent package com. CairngormEvent; import com. The AppController implementation package com. FrontController; import com.

The Command implementation package com. IResponder; import com. Command; import com. LoadEmployeesDelegate; import com. The Delegate implementation package com. AsyncToken; import mx. The View: EmployeesList. AddNewEmployeeEvent; import com. UpdateEmployeeEvent; import com. LogoutEvent; import com. ArrayCollection; import com. ModelLocator; import com.


Professional Cairngorm™ by Jeremy Wischusen



Agile Enterprise Application Development with Flex by Tony Hillerson



Developer Documentation




Related Articles