Listen to this post
Reading Time: 4 minutes

The Basics

Learn design patterns for fun and profit! Design patterns are a useful way to solve a problem once with many languages. A design pattern looks at languages and frameworks as components of a design pattern.

Each design pattern is a three-part rule that expresses a relationship between a certain context, a problem, and a solution. It is a solution to a recurring problem within a certain context.

The more versatile and valuable design patterns can be applied to many diverse languages and frameworks and frame the consequences of using the software design pattern.

Quality software design patterns are named for the concrete problem they are attempting to solve with a template or algorithm.

Software design patterns are a map and not a prescription. Patterns help with defining a why and how within your context, but not when to apply them.

Patterns used in the wrong context and at the wrong time are described as anti-patterns. Identifying and eliminating anti-patterns is a primary responsibility of software developers.

Primary Use Cases

  • If you like saving time, you’ll like design patterns
  • Quickly communicate ideas with your colleagues, and speak the same language despite knowing different underlying tools
  • Solve recurring problems

The Purpose

When creating a design pattern understanding the purpose is where to start. The purpose reflects exactly what the pattern does.

Types of Design Patterns

There are three types of design patterns. Behavioral, creational, and structural.

Creational

In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.

An example is the builder pattern that is used to separate 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. Using the builder pattern allows you to acquire a car, a hotel, and a flight with different workflows.

Structural

In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships among entities.

An example is the module pattern. It is the most common structural pattern you will see in everyday software implementations. The module pattern is often employed as a fundamental concept of a language. In Python, any .py file is a module, along with Terraform where each .tf file is a module.

A module is a self-contained set of code that can run independently of other code.

Behavioral

In software engineering, behavioral design patterns are design patterns that identify common communication patterns among objects. By doing so, these patterns increase flexibility in carrying out communication.

An example of a behavioral pattern is the strategy pattern which is used to adjust how you deal with different classes of data.

Imagine your program accepts multiple payment types. When someone pays with Paypal, your strategy class is different than paying with American Express. Luckily your payment strategy can be achieved with different payment types, and adding a new one is as simple as adding another class.

How To Choose

Choosing the appropriate design pattern to use within your given context and at the right time is a key decision point. Applying the following methodology will help you choose the right software design pattern at the right time.

  1. Read the software design pattern completely from beginning to end to overview the pattern’s usage.
  2. Consider how candidate software design patterns solve your design problem.
  3. Identify what the intent of the design problem is and what it actually does.
  4. Learn what principles the design pattern is based upon
  5. Study how your candidate software design patterns relate to other patterns
  6. Consider what parts of code you want to be able to change without having to redesign your solution

Conclusion

Developing enough software will make you a pattern recognition master. Pattern recognition isn’t limited to software design; we are built at a psychological level to identify patterns to predict the future and stay alive. Identifying, and using software design patterns, might not save your life, but it could save your project.

While software design patterns seem like a surefire way to make the right design choices, be judicious with their use.

Follow this checklist to ensure you’re using software design patterns in the right way.

  1. Is the design pattern appropriate for your context?
  2. Does the problem you’re facing repeat across space and time?
  3. Does the design pattern solve your problem, or does it introduce numerous new problems?

Software design patterns pack a serious amount of power. With that power comes a great responsibility to understand the pattern you are using before you employ it.

I wish you the best of luck with your endless journey with software design patterns!

Learn Software Design Patterns – Beyond the Basics

image_pdfimage_print

Was this post helpful?

Share this post