SOLID Principles
S Single Responsibility

SOLID — 01

Single Responsibility

One class — one reason to change

↓ click to explore

SOLID — 01 / Flow

S

Single Responsibility

A class should have one, and only one, reason to change.

UserManager
BAD — validates + saves + emails + reports
↓ Split by SRP
UserValidator
OK — validates only
UserRepository
OK — saves only
EmailService
OK — emails only
ReportGenerator
OK — reports only
O Open/Closed

SOLID — 02

Open/Closed

Open for extension, closed for modification

↓ click to explore

SOLID — 02 / Flow

O

Open/Closed

Add new features without changing existing code.

Core Plugin
CLOSED — never modified
do_action(“before_save”) — Hook = Extension Point
Your Plugin
OK — add_action() extends without touching core
Another Plugin
OK — add_filter() extends independently
L Liskov Substitution

SOLID — 03

Liskov Substitution

Subtypes must be substitutable for base types

↓ click to explore

SOLID — 03 / Flow

L

Liskov Substitution

If B extends A — B must work wherever A is expected.

Shape (interface)
getArea(): float
Rectangle implements Shape
OK — width × height
Square implements Shape
OK — side²
printArea(Shape $shape)
OK — works with ANY Shape — LSP
I Interface Segregation

SOLID — 04

Interface Segregation

Many specific interfaces over one general

↓ click to explore

SOLID — 04 / Flow

I

Interface Segregation

No client should be forced to depend on methods it does not use.

Worker (fat interface)
BAD — work + eat + sleep — Robot forced to implement all
↓ Split by ISP
Workable
OK — work()
Feedable
OK — eat()
Restable
OK — sleep() + takeBreak()
D Dependency Inversion

SOLID — 05

Dependency Inversion

Depend on abstractions, not concretions

↓ click to explore

SOLID — 05 / Flow

D

Dependency Inversion

High-level modules should not depend on low-level modules.

UserService
depends on Database_Interface ← abstraction
Database_Interface
save() / find() / delete()
MySQL_Database
OK — implements interface
Mock_Database
OK — implements interface — for tests