Learn design patterns to accelerate software development. A design pattern considers languages and frameworks as its components. Design patterns help you solve a problem with many software languages and frameworks.
Each design pattern is a three-part rule expressing a relationship between a specific context, problem, and solution. It is a solution to a recurring problem within a particular context.
High-quality patterns define the consequences of using them and work with many languages and frameworks.
Software design patterns are a map and not a prescription. Patterns help define the why and how within your context, but not when to apply them.
Patterns used in the wrong context at the wrong time are anti-patterns. Identifying and eliminating them is a primary responsibility of software developers.
Primary Use Cases
- Save time
- Quickly communicate ideas
- Solve recurring problems
Understanding a design pattern’s purpose first is an effective approach. Its purpose should reflect what it does.
There are three types of design patterns. Creational, structural, and behavioral.
Creational design patterns manage object creation. A basic form of object creation can result in design problems. Creational design patterns address this by controlling object creation.
An example is the builder pattern which separates the construction of a complex object from its representation.
Imagine you are building an itinerary. When building the itinerary, you’ll need a car, a hotel, a flight, etc. Use the builder pattern to acquire a car, a hotel, and a flight with different workflows.
Structural design patterns ease a design by identifying a simple way to realize entity relationships.
An example is the module pattern. It is the most common structural pattern in everyday software implementations. The module pattern is a fundamental concept of a language. For example, in Python, any .py file is a module, along with Terraform, where each .tf file is a module.
A module is self-contained and runs independently of other code.
Behavioral design patterns identify common communication patterns. These patterns increase communication flexibility.
An example is the strategy pattern which adjusts data type behaviors.
Imagine your program accepts multiple payment types. When someone pays with Paypal, your strategy differs from paying with American Express.
The strategy pattern simplifies adding new payment types with different concerns.
How To Choose
Choosing an appropriate design pattern is a crucial design decision.
Follow these steps to simplify design pattern selection.
- Thoroughly read its description to form an overview.
- Identify the design problem it solves.
- Learn what principles it follows.
- Study how it relates to other patterns.
- Identify code change needs and how it applies.
While software design patterns aid with design choices, be judicious with their use.
Follow this checklist to validate its usage.
- Is the pattern appropriate for your context?
- Does the problem it solves repeat across space and time?
- Does the pattern solve your problems, or does it introduce new problems?
Software design patterns pack a serious punch. With power comes great responsibility, so strive to understand a pattern before using it.
Best of luck on your endless journey with software design patterns!
Learn Software Design Patterns - Beyond the Basics
- Advanced Design Patterns: Design Principles — LinkedIn
- [Clean Code Applied (Clean Coders Video Series): Building a Java Web Application with Software Craftsmanship] — O’Reilly
- Design Patterns Overview — Pluralsight
- Modeling and Schema Design Patterns for Document Databases — Pluralsight
- Mastering Python Design Patterns: A guide to creating smart, efficient, and reusable software, 2nd Edition — Amazon
- Design Patterns: Elements of Reusable Object-Oriented Software — Amazon
- Microservices Patterns: With examples in Java — Amazon
- [Head First Design Patterns, 2nd Edition] — O’Reilly
- [Software Architecture Design Patterns in Java] — O’Reilly