Announcing Design Python Pattern of the Week
Every Monday I'll be describing a software design pattern and providing an implementation in Python. I'll focus on mapping the pattern's intent into idiomatic Python. Email me or leave a comment if you are interested in seeing a specific pattern. I'll start out with some GoF patterns and then work toward the more enterprisey ones.
What are design patterns?
Certain problems come up over and over again when designing software. Things like localizing the creation of objects and wrapping APIs seem to come up in most projects I have worked on. Design patterns are elegant and extensible solutions to these and other software design problems. A pattern is not a complete design. It is advice for dealing with parts of your design. It describes a set of principles and the situations where they apply. A real design would likely consist of many patterns.
Patterns are discovered, not invented, by finding similar solutions in a wide variety of software systems. This ensures that they are true patterns and not a one-off solutions. This also means that the solutions are battle tested. You are not the first one to use them.
Do you need to know patterns?
They are very important when building large systems. Using patterns will relieve you from having to rediscover solutions to problems that others have already solved. Systems built using patterns are also easier to maintain, because developers familiar with patterns will have less of a learning curve.
Having a firm understanding of patterns will make your designs better. Think of patterns as lessons from master software designers. They have already taken the time to solve this problem by looking at many alternatives. This is the best solution they could come up with.
Why is this different from the countless patterns books?
Most modern pattern books use Java in their examples. The Java implementation can sometimes hide the pattern's intent especially if you're not a Java programmer. The implementation may look dramatically different in other languages. So if you're like me and you use Python, the examples are almost worthless.
While translating the examples directly into Python is possible I wouldn't suggest it. The resulting code would probably not be Pythonic and would instead stink of Java. We can do better than that.
More Information
Use Google, it is your friends. The discussion on Wikipedia is pretty good and the Hillside.net Patterns Library has a large amount of good information.