godz.online
Back to tools

TLDR reference

Design patterns

A searchable cheatsheet of software design patterns - the 23 Gang of Four patterns plus common modern ones - each with a short PHP snippet and a one-line intent. Type to search, or filter by group. Everything runs in your browser.

29 shown

How it works

A searchable cheatsheet of software design patterns: the 23 classic Gang of Four patterns - grouped into Creational, Structural, and Behavioral - plus a handful of modern, architectural ones such as Dependency Injection, Repository, and Specification. Each card pairs the pattern name with a short PHP snippet showing its shape and a one-line note on what it does and when to reach for it. Type to search by name or idea - "singleton", "observer", "wrap", "undo" - or use the chips to browse one group.

The snippets are PHP, but the ideas are language-agnostic: a pattern is a named, reusable solution to a recurring design problem, and a shared vocabulary for talking about structure. Use this as a quick refresher before an interview, a nudge when a class is getting tangled, or a map of the options when you are not sure which shape fits. Everything is static and runs in your browser, so the lookup is instant and works offline once the page has loaded.

Example. Searching "factory" lines up the creational options: a Factory Method defers the choice of class to a subclass, while an Abstract Factory builds a whole family of matching objects. Filtering by the Behavioral chip groups the patterns that manage how objects collaborate - Observer, Strategy, Command, State - so you can compare the ones that solve similar problems side by side.

FAQ

What are the three Gang of Four pattern categories?

The original 23 patterns from the "Design Patterns" book are split into three groups by what they are about. Creational patterns deal with how objects are made (Singleton, Factory Method, Abstract Factory, Builder, Prototype). Structural patterns deal with how objects are composed into larger structures (Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy). Behavioral patterns deal with how objects communicate and share responsibility (Observer, Strategy, Command, State, and the rest). This cheatsheet adds a fourth group for widely-used modern and architectural patterns that came later.

Are these patterns specific to PHP?

No. Design patterns are language-agnostic solutions to recurring design problems - they apply to any object-oriented language, from Java and C# to Python and TypeScript. The snippets here are written in PHP because that is what this site is built in, but the structure is what matters, not the syntax. A few patterns are nearly invisible in some languages because the language already provides them: PHP gives you Prototype through clone and Iterator through generators, for example.

What is the difference between the Singleton pattern and dependency injection?

Both give you a single shared instance, but they differ in who is in control. A Singleton creates and hands out its own instance through a global static method, so any class can reach for it from anywhere - which hides the dependency and makes the code hard to test in isolation. Dependency injection instead passes the shared instance in from outside, usually through the constructor, so a class declares what it needs and a container wires it up. In modern frameworks like Symfony you almost always want dependency injection; the container already guarantees one shared instance per service.

Do I need to memorise all 23 patterns?

No. The value is in recognising the shape of a problem and knowing a proven solution exists, not in reciting definitions. A handful come up constantly - Strategy, Observer, Factory, Adapter, Decorator, and Dependency Injection - and are worth knowing well. The rest are useful to recognise so that when you meet one in a codebase or need one, you know what to look up. Patterns are a vocabulary, not a checklist: reach for one because it fits, not to tick a box.