The Anti Patterns Misconception

I kicked off this Software Patterns category with A Brief Introduction to Software Patterns. The following is a short quote from that post which sums up, in a nutshell, what that post had to say:

A pattern is basically a capturing of a problem (in context) together with a solution to that problem

Another pattern related term that is in common use in software development is “anti-pattern”. The concept of the anti-pattern is something of a misconception, so here I’d like to take a look at why it’s a misconception.

It is very convenient to talk about “good” and “bad” practices, but this is problematic in itself because it oversimplifies the world far too much! Please take the following points into account:

  • One of the important things a pattern captures is the context in which a problem is occurring, and hence the context in which the solution is applied
  • In addition, a pattern also captures the tradeoffs accepted in applying the solution

What constitutes “good” and “bad” practice depends largely on what one is trying to do in the first place, and on the surrounding circumstances. Further, a solution which is a good one subject to certain context/tradeoffs might be a bad one subject to different context/tradeoffs.

The anti-pattern misconception starts with another misconception – that a pattern captures a best practice solution to a problem in context, which is not correct. Certainly many known patterns do capture best practice solutions, but the best practice part of it is not part of the definition of what a pattern is. It just so happens that what people are usually interested in is the best way to do things, and hence enthusiasts have documented many patterns capturing best practice solutions.

Just suppose for a minute that the commonly believed myth about patterns capturing best practice was true. That leaves a reason – a need in fact – to capture wrong/bad/worst practices, to help developers recognise them and understand why they are wrong/bad. This is where the term anti-pattern comes in. In reality anti-patterns are just patterns – that is, patterns in which the solution captured is a bad one. In fact, the anti-pattern captures a solution that does not satisfy the acceptable tradeoffs, does not work in the context, or both. A pattern captures a solution to a problem – be it a good, bad, or indifferent one, hence the anti-pattern concept is actually meaningless. Unfortunately, in my experience, write-ups and discussions of anti-patterns either do not take into account that the world is not so clear cut, just choose to ignore it, or both.

Leave a Comment

Your email address will not be published. Required fields are marked *