Cheat sheet · Build products
Design Patterns cheat sheet
FreeFor developers who want a compact reference to the 23 classic design patterns and the SOLID principles, to use in code reviews and design discussions. Each pattern has its intent, when to reach for it and a short TypeScript sketch, followed by a map from common problems to the pattern that fits.
Chapters
8 chapters · 45 concepts
1How to use patternsWhat a design pattern is, the three families in the Gang of Four catalogue, and the two principles most patterns are built on.6 concepts
- 1Design patternA named, reusable solution to a design problem that keeps recurring in object-oriented code.
- 2Creational, structural, behaviouralCreational patterns control how objects are made (5).
- 3Program to an interfaceWrite code against what an object can do (an interface or abstract type), not which concrete class it is.
- 4Composition over inheritanceBuild behaviour by holding other objects and delegating to them, rather than by deep subclass chains.
- 5Reading pattern diagramsPattern books draw UML class diagrams: a box per class, a hollow triangle arrow for "implements or extends", a plain arrow for "uses", and a diamond for "holds…
- 6When not to use a patternA pattern adds classes and indirection.
6 in this chapterOpen this chapter2Creational patternsThe five patterns that decide how objects get created, so calling code does not depend on concrete classes or messy constructors.5 concepts
- 1Factory MethodIntent: let a method decide which class to instantiate, so callers ask for "a transport" without naming the class.
- 2Abstract FactoryIntent: an interface for creating whole families of related objects, with one concrete factory per family.
- 3BuilderIntent: construct a complex object step by step, separating how it is assembled from what it ends up as.
- 4PrototypeIntent: create new objects by copying an existing, configured instance instead of building from scratch.
- 5SingletonIntent: ensure a class has exactly one instance and give global access to it.
5 in this chapterOpen this chapter3Structural patternsThe seven patterns that compose classes and objects into larger structures while keeping them flexible.7 concepts
- 1AdapterIntent: convert the interface of an existing class into the one your code expects.
- 2BridgeIntent: split an abstraction from its implementation so the two can vary independently.
- 3CompositeIntent: compose objects into trees and treat single objects and groups the same way.
- 4DecoratorIntent: add behaviour to an object by wrapping it in another object with the same interface.
- 5FacadeIntent: one simple entry point in front of a complicated subsystem.
- 6FlyweightIntent: share the common, unchanging part of many similar objects instead of storing it in each one.
- 7ProxyIntent: a stand-in object with the same interface that controls access to the real one.
7 in this chapterOpen this chapter4Behavioural patterns: requests and eventsPatterns for passing requests, events and state between objects without tying them tightly together.6 concepts
- 1Chain of ResponsibilityIntent: pass a request along a chain of handlers until one handles it or the chain ends.
- 2CommandIntent: turn a request into an object with everything needed to perform it, and often to undo it.
- 3IteratorIntent: walk through a collection one item at a time without exposing how it is stored.
- 4MediatorIntent: objects talk through one mediator instead of referring to each other directly.
- 5MementoIntent: capture an object's internal state as a snapshot so it can be restored later, without exposing its internals.
- 6ObserverIntent: when one object changes, all objects subscribed to it are notified automatically.
6 in this chapterOpen this chapter5Behavioural patterns: varying behaviourPatterns for swapping algorithms, changing behaviour with state, fixing a skeleton of steps, and adding operations to object structures.5 concepts
- 1StrategyIntent: define a family of algorithms behind one interface and choose one at run time.
- 2StateIntent: an object changes its behaviour when its internal state changes, as if it changed class.
- 3Template MethodIntent: a base class fixes the steps of an algorithm and lets subclasses fill in some of them.
- 4VisitorIntent: add new operations to a fixed set of classes without changing them, by moving each operation into a visitor object.
- 5InterpreterIntent: represent the grammar of a small language as classes and evaluate sentences by walking the tree.
5 in this chapterOpen this chapter6SOLID principlesThe five principles behind maintainable object-oriented code, each with the smell that tells you it is being broken.5 concepts
- 1Single Responsibility PrincipleA class or module should have one reason to change: it answers to one actor or concern.
- 2Open/Closed PrincipleCode should be open for extension but closed for modification: add behaviour by adding new code, not by editing working code.
- 3Liskov Substitution PrincipleAny subtype must be usable wherever its base type is expected, without surprising the caller.
- 4Interface Segregation PrincipleMany small, focused interfaces beat one large one; no class should be forced to implement methods it does not use.
- 5Dependency Inversion PrincipleHigh-level policy should depend on abstractions, and low-level details should implement them; neither depends directly on the other.
5 in this chapterOpen this chapter7Principles beyond SOLIDShort rules that sit next to SOLID in code reviews, and the anti-patterns that appear when they are ignored.6 concepts
- 1Dependency injectionAn object receives its collaborators from outside, usually through its constructor, instead of creating them itself.
- 2DRYEvery piece of knowledge should have one authoritative place in the code.
- 3KISS and YAGNIPrefer the simplest design that works (KISS), and do not build for requirements you do not have yet (YAGNI).
- 4Law of DemeterA method should talk only to its own fields, its parameters and objects it creates, not reach through chains like
order.customer.address.city. - 5High cohesion, low couplingCohesion: things inside a module belong together.
- 6Common anti-patternsRecurring bad shapes: the god object that knows everything, spaghetti code with tangled control flow, copy-paste programming, and magic numbers.
6 in this chapterOpen this chapter8Choosing a patternMap the problem in front of you to a pattern, and recognise the patterns already inside the frameworks you use.5 concepts
- 1Problem to pattern mapA quick lookup from symptom to candidate pattern.
- 2Patterns you already useExpress and Koa middleware is Chain of Responsibility, DOM events are Observer, Java I/O streams are Decorators, Spring beans default to singletons, and React…
- 3Patterns and first-class functionsIn languages with first-class functions, Strategy, Command and Template Method often shrink to passing a function, and Iterator becomes a generator.
- 4Telling similar patterns apartAdapter changes an interface; Facade simplifies a subsystem.
- 5Refactoring towards a patternStart with simple code and introduce a pattern when duplication or a growing conditional shows the need, in small tested steps.
5 in this chapterOpen this chapter- 9Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.51 terms
About this sheet
All 23 Gang of Four patterns with intent, when to use and a TypeScript sketch, plus SOLID, related principles and a problem to pattern map.
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allBest practices
See all- Python Best PracticesWrite Python that stays maintainable: supported versions, pyproject and lockfiles, Ruff, type hints, errors, logging, concurrency, pytest and security.
- TypeScript Best PracticesModern TypeScript best practices for 2026: strict settings, TypeScript 7, modeling data with unions, safe narrowing, runtime validation, generics and typed linting.
- Secure Coding Best PracticesWrite code that resists attack: untrusted input, validation, parameterized queries, output encoding, safe parsing, uploads, SSRF and errors that fail closed.
Checklists
See all- Pull Request Checklist: Before You Open a PRA pull request checklist to run before you ask for review: scope and size, a clean diff, tests, a clear description, safe releases and a tidy branch, each with a way to verify it.
- Career Switch into Tech ChecklistMove into software from another field step by step: choose a direction, follow a learning plan, build proof of skill, use your previous domain, network, plan your runway and target a first role.
Project structures
See all- Python package and CLI project structureA command line tool published to PyPI, laid out the way the Python Packaging User Guide and uv recommend: a src layout, one pyproject.toml for metadata and every tool, a thin Typer CLI over plain, testable modules, and releases uploaded by GitHub Actions with trusted publishing. The example is mdlinks, a tool that finds broken links in Markdown files. For students who have written Python scripts and want to ship one that strangers can
pip install. - TypeScript npm library project structureA small, typed npm package (a retry helper) built the way modern libraries ship in 2026: TypeScript source in
src, bundled by tsdown intodistwith type declarations and anexportsmap, tested with Vitest, checked with publint and Are the Types Wrong, versioned with Changesets and published from CI with npm provenance. For students who want to publish their first package, and for anyone whose package works locally but breaks for users. - Flutter project structureFor anyone building one Dart app for Android, iOS and the web. The tree starts from what flutter create gives you and grows into a feature-first lib/ folder, where each feature keeps its own data, domain and presentation code, then adds tests at every level, flavors, release signing, crash reporting and, for large teams, a melos workspace of local packages.
Career questions
See all- What should I learn first to become a software engineer in 2026?Learn one language properly, then Git, the command line, how the web works and basic SQL, and build small things with them from week one. AI tools change how you write code, not what you need to understand. Pick a direction only after the foundations feel boring.
- Should I learn Python or JavaScript first?Choose based on what you want to build. JavaScript if you want web development, since it runs in every browser. Python if you are drawn to data, AI, automation or backend scripting. Both are excellent first languages, and the second one is far easier once you know the first well.
- I understand tutorials but cannot build anything myself. Why does coding feel so different when I am alone?Tutorials train recognition, not production. When you follow along, someone else makes every decision. Building alone requires you to break a problem down and make choices, which is a separate skill. Build it with small projects, planning on paper first, and a rule to struggle before you look anything up.
Cheat sheets
See allStuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com