According to this video here [@ 7:50] Google is recommending the use of the Command pattern on top of its request handling API. There is also a helpful looking project gwt-dispatch that implements that pattern.
According to gwt-dispatch documentation I need to create four classes for each command:
- an action (e.g. command)
- a result (e.g. response)
- an action handler
- a module
Assume my service API has 100 methods across 8 BSOs, can somebody explain to me why I want to create nearly 400 new classes? What awesomeness does this p开发者_如何学Pythonattern buy?
One good reason to use the command pattern is, when you want to pass the command object to further delegates - so instead of copying all the arguments, it's easier to just pass the command object around. It's also useful for gwt-dispatch's rollback functionality (or the undo/redo functionality e.g. in Eclipse's UndoableOperations).
It helps to provide several variations of commands by using different constructors, and subclasses of commands.
I would not suggest to always use the pattern, but you don't save as much as you think, when you don't use it: You will often need result objects anyway - and it's possible to reuse the same return objects. In other cases, you can use the same object for the command and for the result.
The module can be used for multiple commands.
精彩评论