Cairngorm is based on Model View Controller (MVC) framework, specifically designed to facilitate complex state and data synchronization. Over the past few years, Cairngorm architecture has been hugely embraced for developing enterprise Flex applications. While there are a lot of. For the love of GOD, don’t use Cairngorm (2) as a framework. Use either RobotLegs or Parsley. Both of which has awesome documentation.
|Published (Last):||1 December 2008|
|PDF File Size:||10.29 Mb|
|ePub File Size:||5.8 Mb|
|Price:||Free* [*Free Regsitration Required]|
Whenever the subject of third-party architectural frameworks is raised at a gathering of Flex developers, the developers are quick to start explaining how they use and like a particular framework. Many enterprise developers, especially those who came to Flex after spending some time developing Java EE applications, cairngor, know that using these frameworks is the right thing to do. What are the benefits of using architectural frameworks? This chapter offers some answers as to what you should expect of a framework built on top of the Flex framework.
The goal of any well-designed framework is to make the process of software development and maintenance easier. There are different ways of achieving this goal. Some people prefer working with frameworks that are based on the Model-View-Controller pattern; others like dealing with libraries of components. Each approach has its benefits and costs.
In this chapter, you will learn how to build the same application using several frameworks or component libraries used by Flex developers. Imagine a new housing development.
Flex MVC Architecture (CAIRNGORM)
For some pieces of property, the builder has already erected the frames for certain house models, but other pieces of property have only piles of construction materials guarded by specially trained dogs. By the entrance to the new community, you see a completely finished model house with lots of upgrades. Purchase one of five prearchitected models see those houses that are framed?
The frames are pretty much ready; you just need to select windows, flooring, and kitchen appliances. Now, to draw some cairngrom to the software engineering world, Case A is the equivalent of purchasing an all-encompassing enterprise software package that comes with 2, database tables and thousands of lines of code, with a promise ccairngorm cover all the needs of your organization.
Case B is the equivalent of a software framework fles you must code in ways that operate by the rules of the framework, adding your own application-specific logic where appropriate. Often such frameworks are intrusive—you have to include in your application code hooks to build your software on architecthre pillars of the selected cairbgorm. Case C gives you complete freedom of choice, as long as you have all the components and the know-how to put them together.
Adobe Flex architectyre you with an extendable framework that you can use as a solid starting point for your business application. Along with that, there are a number of third-party frameworks and component libraries created with the same noble goal: As Flex is already a framework, you should have very strong reasons to create another one.
Flex has extendable components and events, and when you work in a team of developers, ij of them may have a different understanding of how custom components should find and communicate with each other, how to properly organize the project, and how to make a team work more productively. At the time of this writing, there are about a dozen Flex frameworks from which you can choose to help you organize your Flex project.
Each of these frameworks has the same goal: Of course, as the readers of this book may have a different understanding of what easy means, the authors decided to show you how you can build the same application using each of the frameworks or libraries. Each of the reviewed products cairngoorm offered at no charge. The application reads data from the database, displays a list of employees, and architectufe the user to add a new employee or edit an existing employee.
Next, it explores the version of the application written in the Mate framework and published on the AsFusion website. Each of the following sections starts with a cairrngorm introduction of the framework or library, followed by a code walkthrough and conclusions. The application retrieves data from Employee. Although retrieving data from an XML file simplifies the explanation of this framework in this example, it is preferable that you pass the typed data from the server in real-world projects, for example, Java value objects converted into their ActionScript strongly typed peers.
This technique eliminates the need to write a lot of mundane code to convert the startdate from String to Date and the like. The title of this section is a bit of a misnomer, because Flex itself is a framework. But we wanted to stress that you can create an application that reads XML and displays the data in a cairnglrm control without the use of any additional third-party framework or caiirngorm library.
The Flex framework already supports the MVC pattern by separating the View the List control and the data that can be stored in a nonvisual data provider such as ArrayCollection.
Apache Flex – A Practical Guide: Introduction to MVC Architecture of Cairngorm
The data is stored in the data provider employees a. For simplicity, this version does not have error processing, and the Add Employee and Logout buttons are nonfunctional. Because real-world Cairngirm are a lot more complex than this simple application and may contain a hundred or more different views created by multiple developers with data coming flwx different sources, consider using one of the additional frameworks or component libraries to simplify the programming archietcture similar tasks and to better organize the project.
The architectural framework Cairngorm was created by Alistair Caorngorm and Steven Webster while they were working at the company iteration:: It flfx 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 arfhitecture. The Model tier is represented by the class ModelLocatorwhich stores the application-specific data these are often collections flx 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 Cairntorm 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.
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 caurngorm 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 Srchitecture 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.
Agile Enterprise Application Development with Flex by Tony Hillerson
On the application startup, the code dispatches LoadEmployeesEvent and, as if by archotecture, 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 IResponderwhich requires you to add the result and fault methods. By using these callbacks the delegate will return to inn 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 acirngorm manipulations will be needed. Just move the business logic from the delegate right into the execute method of the command architecthre 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 architectture 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 cairngoorm Employees. The Command class updates the model. This model locator stores the data and the state of this application—in particular, the variable employeeListDP architecthre, 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 fled, 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 service calls are made to pass the changed data architectuer the server side for persistence. The View portion of the employee list gets updated automatically as a result of data binding.
Online, you may f,ex 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 2and 6and then decide whether you prefer working with the components cairnyorm 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 Architeecture, each of these modules becomes dependent on the central FrontController located in the main.