Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中实现命令模式?_Java_Gwt - Fatal编程技术网

如何在Java中实现命令模式?

如何在Java中实现命令模式?,java,gwt,Java,Gwt,我看了之后,很难弄清楚服务器端应该如何工作 幻灯片21显示: /** The name Command is taken */ interface Action<T extends Response> { } interface Response { } interface ContactsService extends RemoteService { <T extends Response> T execute(Action<T> action);

我看了之后,很难弄清楚服务器端应该如何工作

幻灯片21显示:

/** The name Command is taken */
interface Action<T extends Response> { }

interface Response { }

interface ContactsService extends RemoteService {
  <T extends Response> T execute(Action<T> action);
}

interface ContactsServiceAsync {
  <T extends Response> void execute(Action<T> action,
      AsyncCallback<T> callback);
}
gwt会在匹配我的精确参数时选择该方法,但事实并非如此。目前我正在使用:

if (action.getClass().getName() == ActionSubclass.class.getName())
{
    return (T) execute((ActionSubclass)action);
}
但这意味着每次添加操作时,我都必须不断地向该方法添加ifs,并且必须使用未经检查的强制转换。有没有更好的方法来实现这一点

注意:从我在其他地方读到的内容来看,命令模式通常会包括Ac子类中要执行的操作,但由于这是为服务器传递一个客户端对象以执行某些操作,因此操作的执行必须分开。

签出和如何使用它

另外,这可能是引用Ray Ryan的IO talk并构建Hello World应用程序的最好文章之一。应用程序使用GWT调度


-JP

我将命令模式与访问者模式结合使用。这使得它的类型安全,易于扩展


服务器端所需的只是一个处理程序存储库,可以与请求对象匹配。有很多方法可以解决这个问题。Visitor是一种方法,但您可以只根据命名约定进行映射,也可以使用注入框架将请求对象映射到该类型的处理程序。

然后由服务器决定如何处理操作对象。正如其他人所说,gwt dispatch是寻找这个故事的服务器端部分的好地方

if (action.getClass().getName() == ActionSubclass.class.getName())
{
    return (T) execute((ActionSubclass)action);
}