Software Design Patterns
A software design pattern is a general, reusable solution to a commonly occurring problem in software engineering - something like a blueprint or a template. In object-oriented systems, a design pattern explains the problem, the solution, and its consequences, including examples and tips for implementation.
It’s important to understand that a design pattern is not a finished design you can directly implement into your code. However, they can help you save time by providing tried-out and trusted development paradigms.
Why Use Design Patterns?
The purpose of design patterns is simple - to provide structure. By giving you a basic framework for problem-solving, they can speed up the development process.
Generally speaking, using design patterns will make your code more flexible, reusable, and maintainable. They provide valuable insight gained through years of practical experience, as well as a common vocabulary for discussing code in larger teams. Another plus is that learning design patterns will help you understand new libraries more quickly and improve your object-oriented skills.
Types of Design Patterns
According to GoF, design patterns can be broken into 3 main categories:
- Creational patterns
- Structural patterns
- Behavioral patterns
1. Creational Patterns
As the name suggests, creational patterns are made for creating objects. These patterns aim to prevent problems by giving you more control over object creation. Depending on what they use, they can be divided into class-creation patterns and object-creational patterns.
Creational patterns include:
- Abstract Factory
- Builder
- Factory Method
- Object Pool
- Prototype
- Singleton
2. Structural Patterns
The goal of these patterns is to define how to combine objects to get new functionality. They make it easier to operate and develop applications with independent class libraries by pointing out entity dependencies.
Structural patterns include:
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Private Class Data
- Proxy
3. Behavioral Patterns
These patterns deal with inter-object communication. The goal is to add flexibility to solutions involving communication between objects by assigning them roles and responsibilities.
Behavioral patterns include:
- Chain of responsibility
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Null Object
- Observer
- State
- Strategy
- Template method
- Visitor
Conclusion
Design patterns are great for providing “basic” solutions, but dealing with a specific problem means plenty of solution variations. Keep in mind that design patterns are not a “one size fits all” kind of deal. To make a design pattern fit, you'll usually need to generalize either your problem or its solution. Just like your retirement pension, you probably shouldn’t rely on it alone.
If you’re looking for examples of how to use these patterns in practice, we recommend reading Head First Design Patterns or Design Patterns: Elements of Reusable Object-Oriented Software.
If you already know your stuff and are looking for new professional challenges, send us a message at [email protected] or check out our Digihey Career Page - We’re always looking for tech enthusiasts to join our team!
__
Written by: Helena Grahovac