我看了"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子類中採取的操作,但是因爲這是爲服務器傳遞一個客戶端對象,因此需要執行一些操作行動必須分開。