Java Reference
In-Depth Information
the responsibilities of programmer and graphics designer is referred to
as separation of concerns .
Difficult maintenance. One result of this design is that making a change
in the business process is difficult without a corresponding change in
the code that returns the HTML to the client, the code that reads from
the business model, the error-handling code, and the data-marshaling
code. Bugs in both the presentation and the business logic must be
maintained from the same place in the same way, even though the most
efficient methods for each are very different.
Poor reliability. This design makes it hard to spot bugs and easy to inject
them. As a rule, the brain does a much better job grasping smaller
scripts and scripts with a much more limited purpose.
Little reuse. Because there are no business objects and no user interface
templates, the most common reuse mechanism in this environment is
cut and paste, which leads to dual maintenance and the proliferation of
bugs throughout the system. In most organizations, cut-and-paste pro-
gramming is responsible for more bugs than the next two problems
combined. Y2K might be the best example. In this Y2K joke, the con-
sultant says, “I have good news and bad news. The good news is that
you only have three Y2K bugs. The bad news is that they have been pro-
liferated through your enterprise 250,000 times.” Cut and paste kills.
Causes of the Magic Servlet
The Magic Servlet can be found just about anywhere these days. The domi-
nant feature is the encapsulation of model, view, and controller in a single
method. This antipattern takes many forms. None of the intermediate refac-
toring steps that we will take goes quite far enough. Table 3.2 shows the
causes of the Magic Servlet.
A servlet architecture can easily become the dominant organization for a
program. The servlet alone is not enough. For all but the simplest applica-
tions, the servlet should only be the controller, and it should marshal view and
model logic. Discipline is the best weapon against the Magic Servlet
antipattern. Clear and concise design on each project doesn't cost time—it
saves time. If you do find yourself looking down the barrel of a 10 KB servlet,
don't panic. Refactor.
Search WWH ::

Custom Search