This document is from the authorized Flex curriculum written by learn the basics of building Flex applications using the Cairngorm framework. Flex frameworks are software libraries that assist developers in building rich internet Cairngorm is one of the primary open-source software frameworks for application Hello World Example using Cairngorm · Official Adobe Cairngorm Site. I have just constructed my first Cairngorm application: an Adobe Flex application that uses the Cairngorm application framework, implementing (For example, a user types their username and password into a login box, this.
|Country:||Papua New Guinea|
|Published (Last):||13 August 2010|
|PDF File Size:||10.87 Mb|
|ePub File Size:||10.3 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:: 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 ModelLocatorwhich stores the application-specific data these are often collections of value objectsa. 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.
Agile Enterprise Application Development with Flex by Tony Hillerson
You can download the source code of this application at http: 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. Please note the use of four global objects: 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 frameeork the CairngormEvent object that may or may not encapsulate some application data for example, some value object that is not used in our caorngorm.
It also implements the interface IResponderwhich 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. Tutofial 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 ciarngorm repeating the same code in cairngom 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 futorial 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 cairngormm 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 employeeListDPwhich 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. Rfamework 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 flfx, 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 Cirngorm developers on your team, however, Cairngorm can give tutotial project a structure that will prevent it from failing.
So, is Cairngorm right for your project? Read Chapters 2and 6and 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.
Introducing Cairngorm | Adobe Developer Connection
Application developers have to write lots frqmework 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 cairngrom 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 tutotial 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 cairnhorm 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. Stay ahead with the world’s most comprehensive technology and business learning platform.
With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more. Start Free Trial No credit card required. Command When a View component fires an event, FrontController finds the Command class that was registered with this event fdamework 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.
AppModelLocator; [Bindable] private var model: The class LoadEmployeesEvent package com. The AppController implementation package com. The Command implementation package com.
The Delegate implementation package com. IResponder; private var service: Object; public function LoadEmployeesDelegate command: The SaveEmployeeEditsEvent event is dispatched: To Use or Not to Use Cairngorm?
It allows separate responsibilities of developers. It allows only one-to-one mapping between events and commands. The framework design is based on singletons, which leads to tight object coupling.