Google I / O 2009のプレゼンテーションとして、RayRyanはGWTRPCを使用するときにコマンドパターンデザインを使用することに言及しました。プレゼンテーションを見ることができます。GAD別名GWTActionDispatcherと呼ばれるライブラリがあり、プレゼンテーションでのRayanの推奨からアイデアが取り入れられています。GADは、ジェネリックスを使用する5つのコンポーネント(クラスとインターフェイス)で構成されています。ジェネリックスがなければ、クライアントコードと、アクションとレスポンスの実装がクライアントとサーバーの間で共有されるサーバーコードで多くの型キャストが行われます。上記の5つのコンポーネントは次のとおりです。
1-
public interface Action<T extends Response> extends Serializable {
}
2-2-
public interface ActionHandler<K extends Action, T extends Response> {
/**
* Handles the provided action and retuns response of it.
*
* @param action the action to be handled
* @return the response to be returned
*/
T handle(K action);
}
3-3-
public interface ActionDispatcher {
/**
* Dispatches the provided action to a proper handler that is responsible for handling of that action.
* <p/> To may dispatch the incomming action a proper handler needs to be bound
* to the {@link com.evo.gad.dispatch.ActionHandlerRepository} to may the dispatch method dispatch the
* incomming request to it.
*
* @param action the action to be handled
* @param <T> a generic response type
* @return response from the provided execution
* @throws ActionHandlerNotBoundException is thrown in cases where no handler has been bound to handle that action
*/
<T extends Response> T dispatch(Action<T> action) throws ActionHandlerNotBoundException;
}
4-
public interface ActionHandlerRepository {
ActionHandler getActionHandler(Class<? extends Action> aClass);
}
アクションがアクションディスパッチャーに渡されると、アクションディスパッチャーはActionHandlerRepositoryを呼び出し、適切なActionHandlerを取得するように要求してから、メソッドハンドルを呼び出します。ここでGADを見つけることができます。
言い換えれば、利点はまったく同じです。instanceofと型キャストが少なくなります。これがお役に立てば幸いです。幸運を。