Anti-Patterns
Annihilating evil with Anti-Patterns
From [FREEMAN] p. 612
The Universe just wouldn’t be complete if we had patterns and no
anti-patterns, now would it?
If a Design Pattern gives you a general solution to a recurring problem in a particular context, then what does an anti-pattern give you?
An Anti-Pattern tells you how to go from a problem to a BAD solution.
You’re probably asking yourself, “Why on earth would anyone waste their time documenting bad solutions?”
Think about it like this: if there is a recurring bad solution to a common problem, then by documenting it we can prevent other developers from making the same mistake. After all, avoiding bad solutions can be just as valuable as finding good ones!
Let’s look at the elements of an anti-pattern:
-
An anti-pattern tells you why a bad solution is attractive. Let’s face it, no one would choose a bad solution if there wasn’t something about it that seemed attractive up front. One of the biggest jobs of the anti-pattern is to alert you to the seductive aspect of the solution.
-
An anti-pattern tells you why that solution in the long term is bad. In order to understand why it’s an anti-pattern, you’ve got to understand how it’s going to have a negative effect down the road. The anti-pattern describes where you’ll get into trouble using the solution.
-
An anti-pattern suggests other patterns that are applicable which may provide good solutions. To be truly helpful, an anti-pattern needs to point you in the right direction; it should suggest other possibilities that may lead to good solutions.
Examples