According to Cairngorm arch开发者_如何学Goitecture, we always have a fault handler in every command class for each service.
How we can create a single Class for handling Fault handler event for all the services.
By "always having a fault handler", do you mean by contract, as in in implementing an interface?
You can write a base command class that all of your other command classes extend. The base can implement the on fault handler and all other sub-classes can optionally override it.
public class BaseCommand implements ICommand
{
public function execute( event:Event ):void
{
}
public function onFault( event:Event ):void
{
}
}
// -- no need to implement onFault in sub-class
public class MyCommand extends BaseCommand
{
public function execute( event:Event ):void
{
}
}
Create a base class that you extend all other classes from, put the fault handler there. Such as: FaultHandlerCairngormCommand extends SequenceCommand implements IResponder
[BaseCommand.as]
public class BaseCommand extends SequenceCommand implements IResponder
{
public function execute( event:CairngormEvent ):void
{
super.execute(event);
}
public function fault( info:Object ):void
{
throw new Error("Generic request failure"); //or handle as you please
}
public function result(data:Object):void
{
throw new Error("The result method implementation defined in IResponder for all extensions of BaseCommand must be overrriden in any sub-class");
}
}
[MyCommand.as]
// -- no need to implement onFault in sub-class
public class MyCommand extends BaseCommand
{
public function execute( event:Event ):void
{
remoteObjectDelegate.doYourServerOperation(this);
}
override public function result(data:Object):void
{
trace("happily handling the data"); //without this override an error will be thrown so the developer will know to correct
}
}
精彩评论