Idiomatic Go Patterns

Design Patterns & Best Practices in Go

Real Go implementations of the full Gang of Four catalog, written around small interfaces, composition, concurrency safety, and explicit errors.

Pattern Categories

Go still uses creational, structural, and behavioral patterns, but it adapts them through interfaces and composition instead of inheritance-heavy class hierarchies.

Published Go Articles

Each article includes working Go source, Go-specific tradeoffs, and guidance on when the pattern helps or hurts.

Creational

Abstract Factory in Go

Create related objects through one factory so whole product families can change together without leaking concrete types.

Creational

Builder in Go

Separate a multi-step construction workflow from the final representation so the same input can produce different outputs cleanly.

Creational

Factory Method in Go

Use constructor functions and small interfaces to select concrete implementations without coupling callers to them.

Creational

Prototype Pattern in Go

Clone preconfigured object graphs when copying is simpler or faster than rebuilding the same structure from scratch.

Creational

Singleton Pattern in Go

Use sync.Once carefully for one-time initialization, and understand when dependency injection is a better fit.

Structural

Adapter in Go

Wrap an incompatible API behind the interface your application already expects so the rest of the code stays unchanged.

Structural

Bridge in Go

Separate an abstraction from its implementation so both sides can vary independently without multiplying concrete types.

Structural

Composite in Go

Treat individual objects and object groups uniformly so recursive tree structures stay simple to traverse and aggregate.

Structural

Decorator in Go

Add behavior around an object dynamically by wrapping it with small focused layers that share the same interface.

Structural

Facade in Go

Provide one simplified entry point over several collaborating subsystems so callers can trigger a workflow without knowing every step.

Structural

Flyweight in Go

Share intrinsic immutable state across many small objects so large collections stay cheaper in memory and easier to manage.

Structural

Proxy in Go

Control access to another object by standing in front of it to add caching, authorization, rate limiting, or lazy loading.

Behavioral

Chain of Responsibility in Go

Build validation and request-processing pipelines with small handlers composed through interfaces.

Behavioral

Command Pattern in Go

Encapsulate operations for queuing, audit history, and undo/redo while keeping Go error handling explicit.

Behavioral

Iterator in Go

Traverse a collection without exposing its internal representation, keeping traversal state separate from the aggregate.

Behavioral

Mediator in Go

Centralize communication between collaborating objects so they depend on a coordinator instead of referencing each other directly.

Behavioral

Memento in Go

Capture and restore object state without exposing internal details so undo and rollback remain explicit and controlled.

Behavioral

Observer in Go

Notify dependent subscribers when state changes so event-driven reactions stay decoupled from the publisher.

Behavioral

State in Go

Change an object’s behavior when its internal state changes by delegating transitions and rules to state-specific types.

Behavioral

Strategy in Go

Encapsulate interchangeable algorithms behind one interface so callers can swap behavior without branching on concrete rules.

Behavioral

Template Method in Go

Define the skeleton of an algorithm once while letting concrete steps vary through narrow hook methods.

Behavioral

Visitor in Go

Add operations across a stable object structure without changing each node type whenever a new operation is introduced.