凯恩戈姆故障处理程序

发布于 2024-10-28 21:03:36 字数 84 浏览 1 评论 0原文

根据 Cairngorm 架构,我们在每个服务的每个命令类中始终有一个故障处理程序。

我们如何创建一个类来处理所有服务的故障处理程序事件。

According to Cairngorm architecture, 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话已封尘 2024-11-04 21:03:36

你所说的“总是有一个错误处理程序”是指契约吗?就像实现接口一样?

您可以编写一个所有其他命令类扩展的基命令类。基类可以实现错误处理程序,所有其他子类可以选择覆盖它。

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 
    {

    }
}

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 
    {

    }
}
霊感 2024-11-04 21:03:36

创建一个基类,从中扩展所有其他类,并将故障处理程序放在那里。例如:
FaultHandlerCairngormCommand 扩展 SequenceCommand 实现 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
    }
}

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文