Java Reference
In-Depth Information
Place resource requests and releases in close proximity, and in the same
method if possible. Also place collection adds and removes in close
proximity. Many of the antipatterns are refactored much more easily
when we also apply common coding standards.
We can often take things a step further by using coding standards as a weapon
against antipatterns. Figure 9.1 shows a process we can apply when fighting
antipatterns. We start with isolated problems. In isolation, a bug or poor
design does not rise to the level of an antipattern. When we have enough
occurrences to cause concern, we document an antipattern. We refactor the
generic antipattern, and then publish a guide that demonstrates how to refac-
tor existing occurrences. Programmers use the antipattern and refactoring
guide to identify and fix existing occurrences. We then put protective mea-
sures in place to prevent the problems from occurring. This is where coding
standards can help. Coding standards range from formatting and style to
usage guidelines or even light structural guidelines. In many cases, these
guidelines can gently steer us away from antipatterns. They are also a conve-
nient collection point for these types of remedies.
Protective Barrier
Isolated
problem
Isolated
problem
Isolated
problem
Isolated
problem
Antipattern
Improved
solution
Refactoring
guide
Protective
barrier
Figure 9.1 Effective use of antipatterns requires a process. In this one, when isolated incidents
occur with sufficient frequency, they are used to document a generic antipattern. The refactored
antipattern is used to build a guide for repairing existing problems, and to stimulate protective
measures.
Search WWH ::




Custom Search