Be A Better Coder
Design Patterns
One of the most important aspects of writing maintainable code is being able to notice the recurring themes in that code and optimize them. This is an area where knowledge of design patterns can prove invaluable.
Design patterns have 3 main benefits -
- They provide solid approaches solving issues in software development using proven techniques that reflects the experience and insights the developers had.
- A pattern usually reflects an out of the box solution that can be adapted to suit our own needs. This feature makes them quite robust.
- When we look at a pattern, there’s generally a set structure and vocabulary to the solution presented that can help express rather large solutions quite elegantly.
Patterns are not exact solutions.
It’s important that we remember the role of a pattern is merely to provide us with a solution scheme. Patterns don’t solve all design problems, nor do they replace good software designers, however, they do support them.
Patterns can encourage us to code in a more structured and organized fashion, avoiding the need to re-factor it for cleanliness purposes in the future. What it means is that if our code is built on proven patterns, we can afford to spend less time worrying about the structure of our code and more time focusing on the quality of our overall solution.
Certain patterns can actually decrease the overall file-size footprint of our code by avoiding repetition-- e.g., reducing the number of functions performing similar processes in favor of a single generalized function — the overall size of our code base can be decreased. This is also known as making code more dry.
If we consider that a pattern represents a best practice, an anti-pattern represents a lesson that has been learned.
Anti-patterns describe a bad solution to a particular problem that resulted in a bad situation occurring. It describes how to get out of said situation and how to go from there to a good solution.
The bigger challenges happen after an application has hit production and is ready to go into maintenance mode. A developer working on such system who hasn’t worked on the application before May introduce a bad design into the project by accident. If said bad practices are created as anti-patterns, they allow developers a means to recognize these in advance so that they can avoid common mistakes that can occur,this is parallel to how design patterns provide a way for us to recognize common techniques that are useful.
If you are interested in venturing down the path of writing your own design patterns, I recommend learning from others who have already been through the process and done it well. Spend time absorbing the information from a number of different design pattern descriptions and take in what’s meaningful to you.