Design Patterns
SOLID, the classic Gang of Four patterns and mobile architecture patterns, with real problems and code in Swift, Kotlin and Java.
- 01
SOLID Principles
The five design principles behind most patterns, shown on one growing checkout codebase, with what each fixes, when it's overkill, and code in Swift, Kotlin, Java and TypeScript.
7–35 min beginner Junior & senior
- 02
Singleton
Guarantee one shared instance with Swift static let, Kotlin object, Java's holder and enum idioms and TypeScript modules, and learn why singletons become hidden global state, how to make them testable, and where lazy initialization races.
4–20 min beginner Junior & senior
- 03
Factory Method
Move object creation into one place, let subclasses or configuration decide which class to create, and use static factory methods for clearer, validated construction, with examples in Swift, Kotlin, Java and TypeScript.
4–25 min beginner Junior & senior
- 04
Abstract Factory
Create families of related objects that must be used together, such as a sandbox or live payment client, tokenizer and webhook verifier, choose the family once at startup, stop code from mixing parts of two families, and know when a DI module or a struct of functions does the same job, in Swift, Kotlin, Java and TypeScript.
4–20 min intermediate Junior & senior
- 05
Builder
Create objects with many optional settings step by step and validate them in one place, and learn when named arguments or options objects make a builder unnecessary, with examples in Swift, Kotlin, Java and TypeScript.
5–30 min intermediate Junior & senior
- 06
Prototype
Create new objects by copying an existing one, such as duplicating an invoice or starting a workout from a template, understand shallow and deep copies, give every copy its own identity, and avoid Java's clone(), in Swift, Kotlin, Java and TypeScript.
4–20 min beginner Junior & senior
- 07
Adapter
Make a vendor SDK, a legacy API or a callback-based library fit the interface your code expects, convert units, errors and callbacks to async/await at the boundary, and keep outside models from leaking into your app, in Swift, Kotlin, Java and TypeScript.
4–20 min beginner Junior & senior
- 08
Decorator
Add caching, logging, retries and metrics to an object without changing it or subclassing it, by wrapping it in objects with the same interface, with examples in Swift, Kotlin, Java and TypeScript.
6–35 min intermediate Junior & senior
- 09
Facade
Give a complicated subsystem one simple entry point, such as a checkout made of cart, inventory, payment and shipping services, keep the facade thin and its steps in a safe order, and stop it from growing into a god object, in Swift, Kotlin, Java and TypeScript.
3–20 min beginner Junior & senior
- 10
Proxy
Put a stand-in with the same interface in front of an object to load it lazily, check permissions, cache remote calls or hide that it lives on another machine, and avoid the classic proxy bugs, from cache keys that mix up users to proxies that frameworks silently bypass, in Swift, Kotlin, Java and TypeScript.
4–20 min intermediate Junior & senior
- 11
Composite
Treat single items and groups of items the same way, such as products and bundles in a cart or files and folders, build tree structures with one shared interface and recursion, and handle the practical problems of cycles, deep trees and expensive totals, in Swift, Kotlin, Java and TypeScript.
4–20 min intermediate Junior & senior
- 12
Strategy
Swap one algorithm for another at runtime, without a growing switch statement, with examples in Swift, Kotlin, Java and TypeScript.
6–30 min intermediate Junior & senior
- 13
Observer
Let objects react to changes without knowing who is listening, from simple listeners to NotificationCenter, Combine, StateFlow, Spring events and RxJS, with examples in Swift, Kotlin, Java and TypeScript.
5–30 min intermediate Junior & senior
- 14
Command
Turn actions into objects you can store, undo, redo, queue and replay, from an editor's undo stack to an offline queue of changes that syncs later, and keep commands serializable and idempotent so they survive crashes and retries, in Swift, Kotlin, Java and TypeScript.
3–25 min intermediate Junior & senior
- 15
State
Replace tangled boolean flags with one explicit state and a transition function, move per-state behavior into state objects when it grows, and handle async results, timeouts and persistence without invalid transitions, in Swift, Kotlin, Java and TypeScript.
4–25 min intermediate Junior & senior
- 16
Template Method
Define the fixed steps of an algorithm once in a base class and let subclasses fill in only the parts that vary, protect the template from being overridden, use hooks for optional steps, and know when functions or Strategy are the better choice, in Swift, Kotlin, Java and TypeScript.
4–20 min intermediate Junior & senior
- 17
Chain of Responsibility
Pass a request along a chain of handlers until one handles it, such as deep links routed to the right screen, then use the same idea as middleware and interceptors that wrap a call, get the order right, always call or deliberately skip the next handler, in Swift, Kotlin, Java and TypeScript.
4–20 min intermediate Junior & senior
- 18
Iterator
Walk through a collection without knowing how it's stored, make your own types work with for loops, avoid changing a collection while iterating over it, and use lazy sequences, generators and async iteration for paged APIs, in Swift, Kotlin, Java and TypeScript.
4–20 min beginner Junior & senior
- 19
MVC, MVP, MVVM and MVI
Split a screen into view, logic and data with MVC, MVP, MVVM and MVI, see how each looks in SwiftUI, Jetpack Compose, Android with Java and TypeScript, and avoid the leaks, stale updates and replayed events that come with each.
4–25 min intermediate Junior & senior
- 20
Repository
Hide where data lives behind a small, collection-like interface that speaks your domain's language, keep queries in the repository instead of filtering in view models, combine network and local storage into one source of truth, and test with fakes that behave like the real thing, in Swift, Kotlin, Java and TypeScript.
4–20 min beginner Junior & senior
- 21
Coordinator
Take navigation out of screens and give it to a coordinator that owns a flow, so screens only report what happened, the same screen works in several flows, child flows finish cleanly and deep links build the right stack, in Swift (UIKit and SwiftUI), Kotlin (Compose) and TypeScript.
4–20 min intermediate Junior & senior
- 22
Dependency injection
Pass a class the things it needs instead of letting it create them, wire everything in one composition root, and test with fakes, with examples in Swift, Kotlin, Java and TypeScript, plus scopes, lifetimes and DI frameworks.
6–35 min beginner Junior & senior
- 23
Unidirectional data flow
Keep each piece of state in one owner, pass it down and send events up, derive values instead of storing copies, hoist state so siblings agree, and use a store with a reducer and effects when state is shared across screens, in Swift (SwiftUI), Kotlin (Compose) and TypeScript (React).
4–20 min intermediate Junior & senior