Java Reference
In-Depth Information
JSP
Customer
command
Policy
Policy
command
Customer
Client
HTML
Servlet
Figure 4.4 This version of the Coarse Command antipattern has been refactored. Commands of
page-level granularity can be factored into logical groups, yielding better readability and reuse at
a slight performance cost.
Steps to refactor coarse or fine commands
Coarse commands place too much code in a single command, impairing reuse. Fine
commands place too little code in each command, forcing too many round-trip com-
munications, harming performance.
First, identify the correct granularity for the command set. Optimally,
the fields that logically belong together and that will usually be used as
a unit should be coupled in a single command.
1
Create a new set of command templates for each new command in the
refactored scheme.
2
Move the appropriate execute and initialize methods from the old
command to each of the new ones for the new organization. Move
applicable instance variables and access methods for the new com-
mand granularity. Delete unused code.
3
Identify primary key relationships for the new model. For example,
though customer-name is customer data, it is necessary to establish a
relationship between a customer and an auto policy. Using key rela-
tionships, it is possible to reduce the size of a command because it is
not necessary to have all of the related fields of a related command.
4
Granularities can also be too fine. In our example, field-level granularity
would be too fine. This antipattern is common for the automation of a com-
mand framework. The three easiest ways to automate commands are based on
Search WWH ::




Custom Search