Given the problems we face with in the real world, designing objected-oriented software became a difficult activity for programmers. In addition, designing reusable and extensible software is even harder, at same time it is essencial for the dynamic software industry that exists today. Because of that, Design Patterns gained popularity in computer science in 1994, after the book Design Patterns: Elements of Reusable Object-Oriented Software, with the promess of speed up the software development process. But, what does it mean and do?
What is Design Patterns?
“Design Patterns describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.” This definition, given by Christopher Alexander, can be applied to every single envinroment, including an arquitecture environemnt or a software development one. So, the purpose of Design Patterns is to leave recorded a solution to a problem that occurs more than once. Thus, when someone faces with a problem that was already recorded, or similar to it, it’s not necessary to lose the same time thinking about its solution. The solution for that problem already exits and you just have to reuse it. That is Design Pattern!
Design Pattern Elements
Now that we know what Design Pattern is, we want to know how to find a pattern to resolve our problem. For that, each pattern has 4 elements used to describe it.
- Pattern name: is a handle we can use to describe a design problem, its solutions, and consequences in a word or two.
- The problem: describes when to apply the pattern. It explains the problem and its context.
- The solution: describes the elements that make up the design, their relationships, responsibilities, and collaborations.
- The consequence: are the results and trade-offs of applying the pattern
Reading this 4 elements, you are able to identify the puporse of each pattern and if it can be applied to your problem. If so, congratulations, you have been awared.
Catalog of Design Patterns
The existing Design Patterns are grouped into the following categories:
- Creational Patterns: Abstract factory, Factory method, Builder, Lazy initialization, Object pool, Prototype, Singleton, Utility.
- Structural Patterns: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
- Behavior Patterns: Chain of responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State,Strategy, Specification, Template method, Visitor, Single-serving visitor, Hierarchical visitor
I will not explain them in details now, but I’ll reserve some future posts to the most importants patterns so we can learn their aplicability.
Design Patterns is a good aproach to solve software’s problems in a reusable way. It happens because some software design requires considering issues that may not become visible until later in the implementation. In this case, it’s important to look at the past, see what had been done to solve problems like the ones that you are having now and, thus, reuse past work (don’t reinvent the whell). Therefore, reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.