Java Reference
In-Depth Information
Mini-antipattern: Fat Commands
In our Java “flights,” we must pay attention to other low-altitude details. One
of these is the composition of our command layer. The command architecture
is powerful because the small, lightweight command is easy to code and main-
tain. Those characteristics make it a convenient place to tack on additional
model logic. If the model is a legacy database or transaction code, we might
not have an alternative. If a fully functional object model powers the com-
mand, it pays to carefully consider alternatives before attaching extra function-
ality to the command layer. Otherwise, functionality will leak into increasingly
bloated commands, and that increasing layer will become more difficult to
manage, as in figure 4.5.
Figure 4.5
The Fat Command antipattern occurs when functionality
belonging in the model, JSP, or servlet creeps into the
command. The design pattern is indistinguishable from a
proper Model-View-Controller pattern, but code
belonging in the controller, JSP, or model sneaks into the
It is also possible for commands to take more of a controller role in some situ-
ations. Some architectures provide a JSP and command layer, without the ben-
efit of an interaction controller. When this occurs, the command will often
take on the role of the controller. Problems with this approach include a
tighter coupling than necessary between the user interface and model and
more complex JSP s, both of which reduce readability and increase the com-
plexity of user interface revision.
Reviewing the JSP antipatterns
In this chapter, we have taken the Triangle design pattern and worked
through some antipatterns that plague it. Most of these patterns deal with
keeping the roles of the base model-view-controller architecture sound. The
JSP layer should only include user interface scripting, and as little Java as it
takes to include the dynamic content. The controller should be used exclu-
sively to control the information flow between client and server. The
Search WWH ::

Custom Search