【发布时间】:2010-01-22 20:13:28
【问题描述】:
我看了"Google Web Toolkit Architecture: Best Practices for Architecting Your GWT App",但我无法弄清楚服务器端应该如何工作。
幻灯片 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);
}
我认为这意味着我可以创造
public ResponseSubclass execute(ActionSubclass action) { ... }
当它与我的确切参数匹配时,gwt 会选择该方法,但事实并非如此。目前我正在使用:
if (action.getClass().getName() == ActionSubclass.class.getName())
{
return (T) execute((ActionSubclass)action);
}
但这意味着我每次添加动作时都必须继续向该方法添加 ifs,并且必须使用未经检查的强制转换。有没有更好的方法来完成这项工作?
注意:根据我在其他地方读到的内容,命令模式通常会包括要在 Ac 子类中执行的操作,但是因为这是传递一个客户端对象,以便服务器对其执行一些操作,所以该操作的执行必须分开。
【问题讨论】: