我看了"Google Web Toolkit Architecture: Best Practices for Architecting Your GWT App",我很难弄清楚服务器端应该如何工作。如何在Java中实现命令模式?
幻灯片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子类中采取的操作,但是因为这是为服务器传递一个客户端对象,因此需要执行一些操作行动必须分开。