Welcome to this new eight part series where we'll discuss about one of the most influential and controversial topics in programming, which is design patterns.
You may be familiar with the term, I can even bet that you've heard a workmate or a colleague talking about Design Patterns before. But, what are they and what benefits bring to the table? Let's take a look.
Design Patterns
A design pattern is a reusable solution to a recurring problem within a given context. It means, they are well tested solutions to general problems in software porgramming, they're usually regarded as best practices by some experts.
Design Patterns were officially presented in the book "Design Patterns - Elements of Reusable Object-Oriented Software" which was written by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. The authors are also known as Gang of Four (GoF).
There were originally 23 Desing Patterns specified by GoF. However, with new programming paradigms and new programming stacks releasing more frequently, we currently don't know the official amount but we expect a much higher number.
Design Patterns can be classified in three main categories:
- Creational Patterns: They deal with object creation mechanisms.
- Structural Patterns: They help designing large structures.
- Behavioral Patterns: They are concerned with algorithms and assigment of responsibilities.
Benefits
The main benefit of Design Patterns is that they provide well-tested solutions to known problems. However, we can also list the following benefits:
- They provide a common language and jargon for programmers. For instance, when a programmer states that he/she implemented "X" pattern in a given class it's usually common knowledge for the rest of the team.
- They help you write code faster by implementing well-known and testable solutions.
- They help you write more legible and maintainable code.
Criticism
Some experts claim that Design Patterns introduce innecesary complexity into your code. This is partially true, Design Patterns have developed some kind of "lazyness" in programmers because they won't look for more simple solutions before going straight to desing patterns, this is specially true on junior developers. Rememeber, there must be a "common" context for using a desing patterns and even then, we must try to look for simpler solutions before implementing a new Design Pattern that you just read.
Design Patterns are good practices, well tested solutions to common problems. They are not some magic recipe to solve all our problems. It's up to you to decide where you apply a specific pattern and how to accommodate it to your chosen language, framework and solution.
Most common Design Patterns
We'll explore the most common and used patterns:
- Singleton
- Strategy
- Observer
- Factory
- Adapter
- Builder
- State
In the next post, we will talk about the Singleton Pattern.
Top comments (0)