« Cairngorm 2.2.1 Released | Main
November 14, 2007
Cairngorm - Commands and Responders
Recently, I've seen a few questions around Cairngorm and how commands and responders fit together when using asynchronous services with Flex. I'd like to clarify a couple of points.
A Command need only implement the Flex IResponder interface if it is to be the responder for an asynchronous service call.
This is probably obvious to many, but I've seen Command classes which implement IResponder, but don't do any ansychrnous service calls and have empty result() and fault() methods. In this cases, the Command should implement the ICommand interface only and not the IResponder interface.
The Command class does not have to be the responder for asychronous service calls.
I've not seen many implementations like this, but the Cairngorm command pattern is designed in such a way that your responder can be an instance of another class, as in this example:
public class AddTaskCommand implements Command
{
public function execute( event : CairngormEvent ):void
{
var addTaskEvent : AddTaskEvent = event as AddTasksEvent;
var task : Task = addTaskEvent.task;
var addTaskResponder : AddTaskResponder = new AddTaskResponder( task );
var delegate : TaskDelegate = new TaskDelegate( addTaskResponder );
delegate.addTask( task );
}
}
public class AddTaskResponder implements IResponder
{
private var task : Task;
public function AddTaskResponder( task : Task )
{
this.task = task;
}
public function result( event : Object ):void
{
//handle the result here
}
public function fault( event : Object ):void
{
//handle the fault here
}
}
This implementation allows better separation of logic and potential reuse of responders, and also makes things easier to test.
Posted by amcleod at November 14, 2007 10:14 AM
Comments
Hi, do you know if QTP with Flex plug-in work with Cairngorm? I was able to record scripts with FlexStore, but not our own application with Cairngorm.
thanks
Posted by: Sherry at November 22, 2007 08:11 PM
Thanks!
I have posted my recent work about Cairngorm on my blog http://www.moorwind.com/read.php?65 .
Cairngorm is great. I used it in this project and it helped me write code clearly. So I decided to share the source. This project is a web manage system(with JSP) and it's still have not finished. So,I will write a quick guide about develop Cairngorm (In Chinese, code commented in English) when I completed this project.
Posted by: Kono at November 24, 2007 02:02 AM
HI Sherry,
Yes, QTP should work with Cairngorm, which is just a few actionscript classes. Have you made you app fully automatable?
Posted by: Alistair McLeod at November 28, 2007 12:44 PM
