vishal patel
Applied in productionFoundationUpdated 2026-09-23

SOLID Principles

Five object-oriented design principles that keep code open to change — single responsibility, open/closed, Liskov substitution, interface segregation, dependency inversion.

oopdesignmaintainability

The five, in one line each

PrinciplePlain EnglishSmell when violated
SSingle ResponsibilityA module should have one reason to change, meaning one actor it servesA "Manager" class edited by every team
OOpen/ClosedAdd behaviour by adding code, not editing tested codeA growing switch (type) in five places
LLiskov SubstitutionSubtypes must honour the parent's contractif (x instanceof Square) checks
IInterface SegregationMany small, client-specific interfacesImplementations throwing NotImplemented
DDependency InversionHigh-level policy depends on abstractions; details implement themBusiness logic imports the DB driver

Open/Closed in practice

diagram
interface BankAdapter {
  detect(text: string): boolean;
  parse(text: string): Transaction[];
}
const adapters: BankAdapter[] = [new HdfcAdapter(), new SbiAdapter(), new IciciAdapter()];
export const parse = (text: string) =>
  (adapters.find(a => a.detect(text)) ?? fail("Unknown bank")).parse(text);
Where I've used it

This is exactly how the bank-statement analyser is structured: one adapter per bank format behind a common interface (Open/Closed + Strategy), with the core ledger normalisation depending only on the interface (Dependency Inversion).

Don't over-apply

SOLID is a set of heuristics, not laws. An interface with exactly one implementation that will never change is just indirection. Apply the principles where change is likely, and use YAGNI everywhere else.

Sources & further learning

Videos, courses, docs and books I recommend for this topic.

Related topics