Design Pattern Evangelist Blog

Smart pointers about software design

Maintained by Jim Humelsine | RSS Feed | Edit on GitHub

Dems D’FFACTS

Seven essential design patterns that should be in every developer’s toolbox


Abstraction of Essential Design Patterns

Gang of Four Struggles

I struggled with the original Design Patterns book by the Gang of Four (GoF). The individual patterns are mostly presented in alphabetical order, which is fine for reference, but it didn’t work for me for learning the patterns. Several of the more complex and less frequently used patterns are near the beginning of the alphabet, and hence near the start of the book. Whereas some of the less complex and more frequently used patterns are near the end of the alphabet, and hence near the end of the book. I became overwhelmed by the complex ones, and I was unable to continue learning the design patterns via the book.

Dems D’FFACTS

Just the Facts Ma'am

I learned the design patterns via other online resources. Some of the design patterns are like hammers and screwdrivers in my toolbox. I use them in many of my designs. Other patterns, not so much. These less used tools are still great tools to have even if I don’t use them as often.

Everyone will have their own favorite set of design patterns, but here are the seven that I personally feel are essential to all developers. When I rattled off some of them in a Zoom call a few weeks ago, my friend Scott Harden blurted out FACTS as an acronym, which covered most of them. When I considered the entire list, I made a few adjustments, and here they are in this acronym order:

Seven Essential Design Patterns in Logical Order

While I love Scott’s acronym to help recall the set of essential design patterns, this is not the order in which I prefer to present them. Some of these design patterns are natural extensions of others. I will introduce them in what I consider logical order with highlights to their basic OO components:

Command

Strategy

Template Method

Adapter

Facade

FactoryMethod

Dependency Injection

Summary

Most of these patterns demonstrate Program to an interface, not an implementation in that most of them have an interface or abstract base class at the top of their diagrams.

Many of these patterns work well together. I think this is demonstrated best with Hexagonal Architecture, which is also known as Ports and Adapters.

Pattern Purpose Key Features Advantages Disadvantages Common Use Cases
Command Encapsulates a request as an object, allowing parameterization and queuing of requests Decouples sender and receiver; supports undo/redo; allows logging of operations Promotes loose coupling; enables flexible request handling Can increase code complexity with many command classes GUI menu actions, macro recording, task scheduling
Strategy Defines a family of algorithms and makes them interchangeable Encapsulates algorithm behavior in separate classes; selected at runtime Improves flexibility; simplifies algorithm variation Increases number of classes; client must be aware of strategies Sorting methods, payment processing, game AI behaviors
Template Method Defines the skeleton of an algorithm, letting subclasses provide some steps Uses inheritance; base class defines structure, subclasses override specific steps Promotes code reuse; enforces consistent process Less flexible than composition; changes in base class affect all subclasses Report generation, game level flow, data parsing
Adapter Converts one interface into another expected by the client Wraps an incompatible class to match the desired interface Enables reuse of existing code without modification Adds extra layers; may reduce performance Integrating legacy code, using third-party APIs, device driver interfaces
Façade Provides a simplified interface to a complex subsystem Wraps multiple subsystems behind a single unified API Reduces complexity; improves readability; hides subsystem details May become a “god object” if it grows too large Library wrappers, SDK simplification, enterprise service gateways
Factory Encapsulates object creation logic in a separate method or class Returns instances of a common interface or superclass; creation is delegated to a factory method Reduces duplication of creation code; decouples client from concrete classes May introduce many small factory classes; can obscure which class is actually created GUI components, parsers, game entities
Dependency Injection Supplies an object’s dependencies from the outside rather than creating them internally Constructor, setter, or interface injection; managed by frameworks or containers Increases testability; promotes loose coupling; improves modularity Requires more setup; may be overkill for small projects Spring Framework, .NET Core services, plugin architectures
Key Differences Behavioral patterns (Command, Strategy, Template Method) focus on execution and algorithm flexibility, Structural patterns (Adapter, Facade) focus on interface and subsystem management, Creational patterns (Factory, Dependency Injection) focus on object creation and wiring Command encapsulates actions, Strategy swaps algorithms, Template Method fixes structure with variation points, Adapter translates interfaces, Facade hides complexity, Factory creates objects, DI injects dependencies Choose based on whether you need flexible execution, simpler integration, or decoupled creation Each pattern solves a specific problem but may add complexity if overused

Previous: Design Pattern Principles

Next: Command Design Pattern

Home: Design Pattern Evangelist Blog