Java Reference
In-Depth Information
It is springtime, and the hills are uncharacteristically green. I am mountain bik-
ing near my home in Austin. I take a fairly remote trail winding through the
rocky Bear Creek pass. It traverses the steep slopes beautifully, alternately sliding
on and off the ridges to provide many technical climbs and screaming descents. I
am winded as I arrive at a particularly technical climb on the Outback trail. I
have not ridden for a long while. Most Outback climbs are not risky because it is
hard to gather dangerous speed. Hills with very steep ledges are usually too diffi-
cult to climb, but this one has teeth. It has enough rocks and ledges to make
abruptly stepping off the bike on this steep terrain an adventure, as my shins
remind me.
There are few good and many bad places to dismount, with cracks that can
snap ankles or knees. Mentally rehearsing my dismount at a demanding ledge
around a blind switchback that I seldom conquer, my mind wanders off the trail.
As I begin to round the tight bend at the bottom to start the climb, my body slips
backward, my front wheel lifts off the ground, my weight abruptly shifts forward,
and my back wheel spins out. I have lost momentum and am still depressingly close
to the bottom. I step off my bike and start to walk it toward the top.
At the top of the hill, barely visible between the cracks, on a large, flat rock is a
huge rattlesnake. It is not in a defensive posture, so there is no rattle and no other
hint to its presence. The snake occupies the very flat rock that I would have landed
on had things gone as in my rehearsed dismount. It seems that my poor condition-
ing and technique today conspired to save me. I shudder, and continue to climb.
Getting off on the wrong foot
The basic gateway into most standards-compliant server-side Java applications
is the servlet : a simple wrapper around a service, implemented in Java and
reached through HTTP . This chapter lays out the most basic antipattern
involving the first layer of server-side Java: the Magic Servlet. Projects bun-
gling this first basic step have little hope for success. After examining the roots
of this antipattern, we will lay out the design, the symptoms, and the problems
of the Magic Servlet antipattern. Then, through a series of refactoring steps,
we will transform this antipattern to the Triangle, a design pattern based on
An early antipattern: The Magic Pushbutton
First, we should discuss an early version of an old antipattern. I encountered
the Magic Pushbutton in many of my early consulting engagements. (Stewart
Nickolas, a well-respected software architect, coined the phrase.) After I
Search WWH ::

Custom Search