Click here to load reader

Cairngorm Microarchitecture

  • View
    19

  • Download
    0

Embed Size (px)

DESCRIPTION

Cairngorm Microarchitecture. Pronunciation. Cairngorm (kârn gôrm) n. yellowish-brown variety of quartz, especially found in Scottish Cairngorm mountain. What is it?. Collection of classes/interfaces against which we can compile - PowerPoint PPT Presentation

Text of Cairngorm Microarchitecture

  • Cairngorm Microarchitecture

  • PronunciationCairngorm (krn grm) n. yellowish-brown variety of quartz, especially found in Scottish Cairngorm mountain.

  • What is it?Collection of classes/interfaces against which we can compileElegant collaboration and partitioning of design responsibilities "microarchitecture" - Provide the skeleton or internal structure of moving parts, around which the flesh and muscle particular to a business domain can be layeredA standard way of building a Flex app.

  • Why use it?Multiple developers working on the project, and run the risk of them all solving the same problem in multiple different ways Unified approach to problemsInject complex functionality in a well understood manner Promote, enable and encourage reuse (business objects, business services, etc.)

  • The Pieces of CairngormModel Locator: Stores all of your applications Value Objects (data) and shared variables, in one place. Similar to an HTTP Session object, except that its stored client side in the Flex interface instead of server side within a middle tier application server. View: One or more Flex components (button, panel, combo box, Tile, etc) bundled together as a named unit, bound to data in the Model Locator, and generating custom Cairngorm Events based on user interaction (clicks, rollovers, dragndrop.) Front Controller: Receives Cairngorm Events and maps them to Cairngorm Commands. Command: Handles business logic, calls Cairngorm Delegates and/or other Commands, and updates the Value Objects and variables stored in the Model Locator Delegate: Created by a Command, they instantiate remote procedure calls (HTTP, Web Services, etc) and hand the results back to that Command. Service: Defines the remote procedure calls (HTTP, Web Services, etc) to connect to remote data stores.

  • Cairngorm 2 Microarchitecture

  • ModelAll client state dataAnything retrieved from serverImplements ModelLocator Cairngorm interfaceThe model locator in an application is a singleton that the application uses to store the client side model.Summary: Model is a Singleton containing data.

  • ViewUser Interface.mxml files w/controls (text fields, combobox, datagrid, etc.)All data is pulled from model via a binding

  • ControllerAllows communication between tiers of application via Events extend class com.adobe.cairngorm.control.CairngormEventCommands implement interfacescom.adobe.cairngorm.commands.ICommandcom.adobe.cairngorm.business.IResponder (optional)Tie Events and Commands together in Controller classConduit between user events and model changes

  • EventsEvents classes usually just a Collection of properties Constructor with params to populate those propertiesUsed to pass data between layers of an application

  • Event - examplepackage com.echoeleven.controller.event{import com.adobe.cairngorm.control.CairngormEvent;import com.echoeleven.controller.ApplicationController;

    public class LoginEvent extends CairngormEvent{public var username:String;public var password:String;public function LoginEvent(username:String, password:String) {super(ApplicationController.EVENT_LOGIN);this.username = username;this.password = password;}}}

  • CommandService to Worker command patternMust implement the Cairngorm Command interfaceIf receiving data from server (e.g. RemoteObject), should also implement Responder InterfaceCommand class must implement execute() methodexecute() usually takes an event argument as a parameter

  • Command - examplepackage com.echoeleven.controller.command{import com.echoeleven.model.ApplicationModel;import com.echoeleven.controller.event.LoginDataChangeEvent;public class LoginDataChangeCommand implements Command{public function execute(eventParam:CairngormEvent):void{var event:LoginDataChangeEvent = eventParam as LoginDataChangeEvent;var appData:ApplicationModel = ApplicationModel.getInstance();

    appData.username = event.username;appData.password = event.password;}}}

  • ControllerTie Event and Command classes together in Controller class constructoraddCommand( ApplicationController.EVENT_LOGIN, LoginCommand );Controller listens for eventWhen event is dispatched, commands execute() method called (by controller)Conduit between user events and model changes

  • Controller Big PictureView event triggered (e.g. click event)Caught by private method in view (mxml file)View method creates instance of event (extending CairngormEvent)View method dispatches that event via CairngormEventDispatcherController catches CairngormEvent and executes associated Cairngorm Command

    private function btnClick( event:Event ):void {var evt:LoginEvent = new LoginEvent(userName.text, password.text);

    CairngormEventDispatcher.getInstance().dispatchEvent( evt );}

  • Example FlowCreate LoginDataChangeEvent classCreate LoginDataChangeCommand classConnect Event to Command in controllerCatch the TextField.change event, and call local function dataChange()Create instance of LoginDataChangeEvent and dispatch itLoginDataChangeCommand.execute() automatically calledexecute() method modifies ModelChange to model reflected in View through binding

  • Service LocatorSingletonAbstracts data communication layerDefines which protocol (http, SOAP, AMF, etc.) and which endpoint params (which service, which channel, etc.)

  • Business DelegateWho should handle the results of a server operation?Avoids attaching result/error routines to data services (e.g. RemoteObject)Allows Command to call remote object method, and handle the result and fault methodsMultiple instances may exist

  • Business DelegateThe Business Delegate typically fulfills its role in collaboration with the Service Locator; it uses the Service Locator to locate and look up remote services, such as web services, remote Java objects, or HTTP services. Once located, the Business Delegate invokes these services on behalf of the class that has delegated responsibility to it for business logic invocation.

  • ReferencesCairngorm DocsBorrowed contents from Scott Talsmas slide