{"post":{"slug":"design-patterns-explained-2026","title":"Design patterns explained in 2026: which ones still matter","excerpt":"The Gang of Four patterns are 30 years old but most still appear weekly in production code. This 2026 guide covers the 10 patterns worth knowing and which to retire.","category":"code","date":"March 27, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">D</span>esign patterns are the shared vocabulary of software engineering. When a senior engineer says \"use a strategy here\" or \"that is a decorator,\" everyone in the room should understand the shape of the solution without writing a line of code. The original 23 Gang of Four patterns were documented in 1994, and while the landscape changed, roughly 10 of them appear constantly in 2026 codebases. The rest have been replaced by language features, frameworks, or better ideas.\n\n## What changed in 2026\n\n- **First-class functions deprecated several patterns.** Strategy, Command, and Template Method in languages with lambdas are just functions — the class-based ceremony is gone.\n- **Frameworks absorbed others.** Spring, NestJS, and React built Observer, Factory, and Dependency Injection into their cores; you use the patterns without naming them.\n- **Functional patterns rose.** Functor, Monad, and Lens patterns from functional programming are now common in typed TypeScript/Rust codebases.\n- **Overuse awareness grew.** The industry became more explicit about pattern fatigue — not every module needs an Abstract Factory.\n\n## The 10 patterns worth knowing in 2026\n\n| Pattern | Category | One-line purpose |\n| --- | --- | --- |\n| Strategy | Behavioural | Swap an algorithm at runtime |\n| Observer / Event emitter | Behavioural | Notify subscribers of state changes |\n| Factory / Factory method | Creational | Delegate object construction |\n| Builder | Creational | Construct complex objects step by step |\n| Decorator | Structural | Add behaviour without subclassing |\n| Adapter | Structural | Bridge incompatible interfaces |\n| Repository | Architectural | Isolate data-access logic |\n| Command | Behavioural | Encapsulate an operation as an object |\n| Proxy | Structural | Control access to an object |\n| Composite | Structural | Treat a tree of objects uniformly |\n\n## Strategy — the most useful pattern\n\nStrategy replaces a tangle of `if/else` or `switch` with a pluggable algorithm:\n\n```ts\ninterface Sorter<T> {\n  sort(items: T[]): T[];\n}\n\nclass QuickSorter<T> implements Sorter<T> {\n  sort(items: T[]): T[] { /* ... */ return items; }\n}\n\nclass MergeSorter<T> implements Sorter<T> {\n  sort(items: T[]): T[] { /* ... */ return items; }\n}\n\nclass DataProcessor<T> {\n  constructor(private sorter: Sorter<T>) {}\n  process(items: T[]) { return this.sorter.sort(items); }\n}\n```\n\nIn Python or JavaScript, a bare function often replaces the interface class entirely.\n\n## Observer — events everywhere\n\nUsed directly in React state management, DOM events, RxJS, and Node.js EventEmitter:\n\n```ts\nclass EventBus {\n  private listeners = new Map<string, Set<Function>>();\n\n  on(event: string, fn: Function) {\n    if (!this.listeners.has(event)) this.listeners.set(event, new Set());\n    this.listeners.get(event)!.add(fn);\n  }\n\n  emit(event: string, payload: unknown) {\n    this.listeners.get(event)?.forEach(fn => fn(payload));\n  }\n}\n```\n\n## Repository — essential for testability\n\nThe Repository pattern abstracts data access behind an interface, letting services remain database-agnostic:\n\n```ts\ninterface UserRepository {\n  findById(id: string): Promise<User | null>;\n  save(user: User): Promise<void>;\n}\n\nclass PostgresUserRepository implements UserRepository { /* ... */ }\nclass InMemoryUserRepository implements UserRepository { /* for tests */ }\n```\n\nPair this with dependency injection and your service layer becomes trivially testable.\n\n## How to pick\n\n1. **Multiple interchangeable algorithms or behaviours?** → Strategy.\n2. **Something happened and others need to know?** → Observer.\n3. **Object construction is complex or conditional?** → Factory or Builder.\n4. **Adding behaviour without changing the original class?** → Decorator or Proxy.\n5. **Bridging two incompatible interfaces?** → Adapter.\n6. **Isolating persistence logic?** → Repository.\n\nWhen in doubt, prefer the simplest code that works. Patterns are applied to a pain point, not prophylactically.\n\n## Common mistakes\n\n**Singleton for shared services.** Singletons create hidden global state, make testing hard, and cause concurrency bugs. Use dependency injection with a single-instance scope instead.\n\n**Pattern stacking.** Abstract Factory of Strategy Builders wrapped in a Decorator is an architecture diagram, not production code. Each layer must earn its place.\n\n**Pattern before problem.** Adding a factory before you have two things to construct. YAGNI applies to patterns too.\n\n**Using patterns as jargon without intent.** Naming something a \"factory\" when it is just a helper function. Patterns communicate structure; use the name when the structure matches.\n\n## What to skip\n\n- **Singleton** as global state — replace with DI.\n- **Abstract Factory** unless you genuinely need families of related objects (rare outside GUI toolkits).\n- **Template Method** — in 2026, pass a callback or use Strategy with a function; no need for inheritance.\n\n## FAQ\n\n**Do I need to memorise all 23 Gang of Four patterns?**\nNo. Know the 10 in the table. Recognise the others when you see them. The rest appear rarely outside textbooks.\n\n**Are patterns language-specific?**\nThe concepts are universal; the implementations vary. A Strategy in Python may be just a callable. Understand the intent, adapt the form.\n\n**Is Repository a Gang of Four pattern?**\nNo — it comes from Domain-Driven Design (Eric Evans, 2003) and Martin Fowler's Patterns of Enterprise Application Architecture. It is now ubiquitous regardless of origin.\n\n**How do functional programming patterns relate?**\nFP patterns like functor (mappable container) and monad (chainable wrapper) solve similar problems to some GoF patterns. They are more composable, less ceremonious, and increasingly common in TypeScript and Rust.\n\n## Where to go next\n\nSee [Dependency injection explained in 2026](/blog/dependency-injection-explained-2026), [Unit testing explained in 2026](/blog/unit-testing-explained-2026), and [Error handling explained in 2026](/blog/error-handling-explained-2026).","hue":321,"metaTitle":"Design Patterns Explained 2026: Which Ones Still Matter","metaDescription":"Practical 2026 guide to software design patterns. The 10 patterns most worth knowing, which language features now replace them","keywords":["design patterns explained 2026","gang of four patterns 2026","software design patterns","strategy pattern","observer pattern","factory pattern","decorator pattern","singleton pattern problems","design patterns typescript","design patterns python 2026"],"tldr":["**Patterns are solutions to recurring design problems**, not algorithms — they communicate intent, not code.","**Strategy, Observer, Factory, and Decorator are the daily-use quartet** — encounter them in every codebase.","**Pattern misuse is worse than no pattern** — forcing Singleton on every service is the most common harm.","**Modern language features replace several patterns** — first-class functions replace Strategy/Command boilerplate.","**Skip:** the Singleton pattern for shared state; use dependency injection instead."],"readTime":"4 min read","wordCount":873},"related":[{"slug":"design-patterns-still-worth-knowing-2026","title":"Design Patterns Still Worth Knowing in 2026","excerpt":"Not every Gang of Four pattern survived contact with modern languages and frameworks. An opinionated 2026 verdict on which still earn their complexity, which got absorbed, and which to retire.","category":"code","date":"July 31, 2026","author":"ByteLedger Team","readTime":"5 min read","hue":320},{"slug":"what-is-a-design-pattern-2026","title":"What is a design pattern in 2026? A practical explanation","excerpt":"A design pattern is a reusable, named solution to a recurring software design problem. This guide explains what they are, the main families, and when using one helps versus hurts.","category":"code","date":"June 9, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":268},{"slug":"design-patterns-singleton-explained-2026","title":"The Singleton Pattern Explained in 2026","excerpt":"Singleton guarantees exactly one instance of a class exists and gives it a global access point. Here is what it is good for in 2026, and why many teams now avoid it by default.","category":"code","date":"July 1, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":320}],"sameCategory":[{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145},{"slug":"graphql-federation-2026","title":"GraphQL Federation: One Graph, Many Teams","excerpt":"Federation composes independently-owned subgraphs into a single API. Here is what it solves, the operational cost it adds, and when a simpler gateway is enough.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":300},{"slug":"hermetic-builds-explained-2026","title":"Hermetic Builds Explained: Same Inputs, Same Output","excerpt":"A hermetic build depends only on declared inputs. Here is what that property gives you, the common leaks that break it, and how to move toward it incrementally.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":130},{"slug":"monorepo-tooling-compared-2026","title":"Monorepo Tooling Compared: What You Actually Need","excerpt":"Monorepo tools solve task orchestration and caching, not repository layout. Here is what each tier provides and how to tell when you have outgrown the simple option.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":150}],"newer":{"slug":"cors-deep-dive-explained-2026","title":"CORS deep dive in 2026: why it exists, how it works, how to fix it","excerpt":"CORS errors are some of the most common and most misunderstood issues in web development. This 2026 guide explains the security model, preflight requests, and the correct server-side fix — not the wildcard shortcut.","category":"code","date":"March 27, 2026","author":"ByteLedger Team","readTime":"5 min read","hue":317},"older":{"slug":"digital-detox-explained-2026","title":"Digital detox explained in 2026: how to disconnect and actually recover","excerpt":"A digital detox is not about willpower or quitting cold turkey. Here is what the research says works in 2026, and a structured plan you can actually follow.","category":"guides","date":"March 27, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":270}}