Software Design

How to Improve your Coding Skills with Software Design Patterns

Architecture Design Pattern OOP

Learning software design patterns can help improve your object-oriented design skills by creating more maintainable code using a collection of time-tested solutions to many common problems.

Design patterns for software were first made famous in the 1994 classic Design Patterns: Elements of Reusable Object-Oriented Software by Gamma, Helm, Johnson, and Vlissides (aka Gang of Four). They took inspiration from a 1977 book, A Pattern Language: Towns, Buildings, Construction, by Christopher Alexander.

Alexander saw that there was a way to break more significant problems down into smaller repeatable patterns that solved specific problems.

“Each pattern 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”

Christopher Alexander
A Pattern Language, 1977

Patterns start to show up over and over in software design as well. It is only the time-tested design patterns that transcend programming languages and their applications. But these patterns allow us to think about high-level concepts and improve software design and maintainability.

Maintaining Software to Survive Over Time

One of the benefits of using design patterns is its ability to create loosely coupled software. Making the opposite, tightly coupled software often leads to many of the bugs and extensibility issues we are forced to deal with, labeled “tech debt.” We all know that software can not last forever, so we need to plan for the enviable. The goal must be to create complex, highly scalable, more easily maintainable, and extendable software over time.

When considering software maintenance, we can organize them into four categories:

  1. Corrective
    To fix existing bugs found in the software.
  2. Adaptive
    Modifications to support a changing environment.
  3. Perfective
    When adding new features and improving existing functionality.
  4. Preventative
    Changes to support future needs of the system.

When something is wrong with the software, we need to fix it. Corrective is the most common we all recognize. But the other three are also required for the software to survive over time. Creating tightly coupled systems causes this software growth to slow as it is often harder to adapt to changing requirements.

Why should we use design patterns?

Using design patterns shows many advantages—mainly creating reusable software.

  1. Reusability
    Re-use design ideas from decades of programmers who have had similar issues.
  2. Sharable
    Easy to discuss topics and use terminology that everyone understands.
  3. Maintainable
    Improve maintainability by using time-tested and production-hardened ideas.

Types of Patterns

A Design Pattern, as outlined in the Design Patterns book, can come in one of three forms.

  1. Creational
    Creational patterns abstract the creation of new objects in the software.
  2. Structural
    Design patterns that focus on how classes are constructed to build larger objects.
  3. Behavioral
    Behavioral patterns describe how objects interact and communicate with one another.

What Makes Up a Design Pattern

  1. Name
    A descriptive name that describes the pattern and solution.
  2. Problem
    Describes which problems the pattern is best applied to.
  3. Solution
    Describes a general template on how a solution can solve the problem.
  4. Consequences
    All architectural designs have pros and cons. This section describes the tradeoffs of using the design pattern.

Creational Patterns

  1. Abstract Factory
  2. Builder
  3. Factory Method
  4. Prototype
  5. Singleton

Structural Patterns

  1. Adapter
  2. Bridge
  3. Composite
  4. Decorator
  5. Facade
  6. Flyweight
  7. Proxy

Behavioral Patterns

  1. Chain of Responsibility
  2. Command
  3. Interpreter
  4. Iterator
  5. Mediator
  6. Memento
  7. Observer
  8. State
  9. Strategy
  10. Template Method
  11. Visitor

How to get started?

You can learn the design patterns and how they are implemented in your programming language. I have enjoyed the following books, but there are many other books on the subject: Design Patterns: Elements of Reusable Object-Oriented Software and Head First Design Patterns: Building Extensible and Maintainable Object-Oriented.

Once you are familiar with the design patterns, start to discuss and use them in design discussions with your team. Propose ways to improve your existing software system and learn what works for your software and situations.

Finally, never stop learning. This will not be a single overnight event but a series of improvements over time.

Conclusion

Design patterns are time-tested software design solutions that can help improve software maintainability. You can improve your software designs and communication by understanding and implementing software design patterns within your teams.

You are creating better software that is both an art and a science. Using design patterns will help you learn from common re-occurring problems many have had before you. This will help you build better software and improve your design skills. It’s a journey, in my opinion, well worth the effort.