Design patterns
Overview
Design patterns are reusable solutions to recurring problems in object-oriented and modular design (creational, structural, behavioral). They improve communication among developers but are not silver bullets—apply when the forces of your problem match the pattern’s intent.
Key concepts
- GoF patterns — Classic catalog from Gang of Four (Gamma et al.).
- Idioms vs patterns — Language-specific habits vs broader structures.
- Anti-patterns — “Silver bullet” misuse (e.g. God object, spaghetti code).
- Functional alternatives — Many patterns map to functions, immutability, and composition.
- Testability — Dependency injection often replaces singleton abuse.
Pattern selection (simplified)
Sample: Strategy in TypeScript (sketch)
type ShippingFn = (weightKg: number) => number;
const ground: ShippingFn = (w) => 5 + 1.2 * w;
const express: ShippingFn = (w) => 18 + 3.5 * w;
function quote(method: ShippingFn, weightKg: number) {
return method(weightKg);
}