Design Patterns

Image from
Shivprasad Koirala

Maybe all of us agree that great ideas should be framed so that all people can appreciate them and learn from them. Similar to when you go to an art museum and appreciate good paintings. In each painting you may appreciate a specific technique that lead to that result.

The phenomenon occurs also in the world of architecture (actually, part of the «design pattern» concept comes from here). Instead of design every new building from zero, architects have manuals with solutions that were already tested and replicated. This way, every new building may be new in shape but it has a common core that ensures reliability.

Something similar happens in the programming world. Usually, developers rack their brains trying to find a solution to a problem that was already solved in an elegant way for another developer. If we think about it, it is a waste of time because it would be better if the solution were clear for everyone.

The paragraphs above describe why someone thought that it would be a good idea to have a compendium of repeatable solutions to common problems in software engineering. This person called Erich Gramma (and some others) wrote a book about it and called it Gang of Four. In Gang of Four, the authors describe 23 design patterns (the classic ones) and include code in C++ and Smalltalk.

Some of the common design patterns are Strategy, Abstract Factory, Singleton, Proxy, Decorator, Iterator, Observer, among others. Learn all of them and being able to use them would be an amazing skill, but to he honest I don’t understand them all.

The misuse of design patterns may lead to bad solutions, as I tried to show in the image at the top of this post. However, they are an amazing tool for most software developers and may come in handy in our life.

I found this cool video about the Decorator pattern in Coursera. You can view it for free and the explanation of the problem and the solution are really clear, also, it only takes a few minutes.

This other video is based on a book from O’Reilly and explains the Strategy pattern very clearly, but it takes more time. I hope you may enjoy it.

Strategy pattern

Finally, the references: