Monday, November 17, 2008

Cairngorm with Flex

Cairngorm is a framework which facilitates to write well structured flex code with MVC architecture. Its Front controller, Model Locator, command and delegate patterns are the main components of the framework. I will try to explain how it works with a simple example application of user search.

  1. App boots up, shows first state
  2. user types in some keywords, clicks the Search button
  3. this fires the doSearch event handler
  4. the doSearch handler creates a CairngormEvent, and dispatches it
  5. the Controller has mapped that type of event to a Command, and thus it runs the command, passing it the event
  6. the Command looks at the event type in the execute function and
    decides what to run, in this case, searchBooks, passing the event’s
    data to the function
  7. search books creates the Business Delegate, and calls its method
  8. the Delegate gets the WebService from the ServiceLocator, fires off the WebService, and waits for a response
  9. if the response is successful, it parses the E4X XML via a Factory to a list of Book ValueObjects
  10. finally, it calls the responder’s onResult function
  11. Since the Command is the Responder, he gets the data, and sets it to the ModelLocator and updates the applications state
  12. The View’s are bound to the state variable and book list in the ModelLocator, so they immediately have their bindings fire
  13. This causes the main app to change state, and show the results DataGrid
  14. The results DataGrid is bound to the books list in the ModelLocator, and shows the results.

No comments: