O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

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

8.2. What Do They Look Like?

There are no classes or interfaces for delegates in the Cairngorm framework. Delegates are mostly used as a convention. However, delegate classes generally do have predictable structures.

The constructor of a delegate allows for the specification of an IResponder class that will handle the results of any remote calls. Each additional method on the delegate represents a particular type of action that can be performed using the service. An example delegate might look like the following:

package delegates
{
    import com.adobe.cairngorm.business.ServiceLocator;
    import mx.rpc.AsyncToken;
    import mx.rpc.IResponder;
    import mx.rpc.http.HTTPService;
    public class ProductsDelegate
    {
        private var locator:ServiceLocator=ServiceLocator.getInstance();
        private var service:HTTPService;
        private var responder:IResponder;
        public function ProuctsDelegate(responder:IResponder)
        {
            this.service = this.locator.getHTTPService("productsService");
            this.responder = responder;
        }
        public function loadProducts():void
        {
            var token:AsyncToken = this.service.send();
            token.addResponder(__responder);
        }
    }
}

You may recall that in the last chapter, on commands, it was stated that when commands need to access remote data, they implement the IResponder interface. In most cases it's the command class that is passed to the delegate constructor. The passed-in IResponder is stored in the responder instance variable. The delegate constructor function also looks up the appropriate service in the constructor ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required