G/Go Pattern Lab

THE GO PATTERN LAB / VOL. 02

23 patterns.
Small Go. Clear thinking.

Already know Java, Scala, Python, or C++? Start with the problem, role mapping, and failure tests. See what Go preserves—and simplifies—from classic GoF.

23 runnable patterns11 OSS repositories40 pinned source ranges

Choose a pattern by the problem

23 / 23 patterns

Creational 5 patterns · How objects are created
Structural 7 patterns · How components compose
Behavioral 11 patterns · How actions, state, and collaboration work

Distinguish similar designs first

Factory Method / Abstract Factory

Replace a creation operation, or replace a related product family together.

Adapter / Decorator / Proxy

Convert a contract; add behavior; control access. Similar shapes, different intent.

Strategy / State / Template Method

Caller-selected algorithm; internal state transitions; a fixed skeleton with hooks.

Command / Memento / Observer

Encapsulate an action; preserve prior state; propagate an event. None implies a transaction.

Run it, then break an assumption

Go 1.23+, standard library only. Download and extract the ZIP, then run this in gof-min. The Test tab shows those exact tests.

go test -race ./...

All implementations and tests are original, runnable minimal examples. Mutable objects are single-owner except where Singleton, Flyweight, and Observer explicitly cover concurrency. Callers provide valid non-nil dependencies. These are not production frameworks.

Direct structure: roles and mechanism align clearly. Go adaptation: the intent appears through composition, functions, or a different representation. Related mechanism: useful comparison, insufficient for a complete classic-pattern claim. These mappings are our analysis.

Go lab verification record · Source metadata