惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
小众软件
小众软件
美团技术团队
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
D
Docker
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
B
Blog
雷峰网
雷峰网
The Cloudflare Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
LLD Foundations: SOLID Principles (Part 2 — LSP, ISP, DIP)
Saras Growth · 2026-05-15 · via DEV Community

Saras Growth Space

In the previous post, we covered:

  • SRP (keep classes focused)
  • OCP (extend without modifying)

Those help you structure code well.

But even with those applied, systems can still break in subtle ways:

  • inheritance behaving unexpectedly
  • classes forced to implement irrelevant methods
  • tight coupling making changes painful

That’s where the remaining SOLID principles come in:

  • LSP (Liskov Substitution Principle)
  • ISP (Interface Segregation Principle)
  • DIP (Dependency Inversion Principle)

LSP — Liskov Substitution Principle

Subclasses should be replaceable for their base classes without breaking behavior.


The classic mistake

Bird:
- fly()

Penguin extends Bird:
- fly() → throws error

Enter fullscreen mode Exit fullscreen mode

This design assumes:

All birds can fly

But penguins cannot.

Now, anywhere Bird is used, substituting it with Penguin breaks the system.


What actually went wrong

The issue is not inheritance.

The issue is:

The base class was designed incorrectly.


Correct approach

Bird:
- eat()
- make_sound()

FlyingBird:
- fly()

Enter fullscreen mode Exit fullscreen mode

Now:

  • Sparrow → Bird + FlyingBird
  • Penguin → Bird

No invalid behavior. No surprises.


Key insight

If a subclass cannot fully support a method, the abstraction is wrong.


ISP — Interface Segregation Principle

Clients should not be forced to depend on methods they don’t use.


The common mistake

Device:
- print()
- scan()
- fax()

Enter fullscreen mode Exit fullscreen mode

Now:

  • A simple printer must implement scan and fax
  • A scanner must implement print

This leads to:

  • unused methods
  • dummy implementations
  • confusion in design

Correct approach

Split interfaces:

Printable → print()
Scannable → scan()
Faxable → fax()

Enter fullscreen mode Exit fullscreen mode

Now:

  • Printer → Printable
  • Scanner → Scannable
  • All-in-one → Printable + Scannable + Faxable

Each class implements only what it needs.


Key insight

Smaller, focused interfaces lead to cleaner and more flexible systems.


DIP — Dependency Inversion Principle

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


The common mistake

NotificationService → EmailSender

Enter fullscreen mode Exit fullscreen mode

This creates tight coupling.

Problems:

  • Switching to SMS requires code changes
  • Adding new channels becomes harder

Correct approach

Introduce abstraction:

Notification:
- send()

EmailNotification → send()
SMSNotification → send()
PushNotification → send()

Enter fullscreen mode Exit fullscreen mode

Now:

NotificationService:
- notify(notification)

Enter fullscreen mode Exit fullscreen mode

The service doesn’t care about implementation details.


Important design detail

Who decides which notification to send?

The caller (e.g., OrderService)

This keeps:

  • NotificationService simple
  • System extensible

Key insight

Depend on behavior (interfaces), not concrete implementations.


Bringing it all together

These three principles solve different kinds of design problems:

  • LSP → prevents broken inheritance
  • ISP → prevents bloated interfaces
  • DIP → prevents tight coupling

Combined with SRP and OCP, they give you:

A system that is stable, flexible, and easy to extend


A practical way to remember

When designing, ask:

  • Will this subclass behave correctly? (LSP)
  • Am I forcing unnecessary methods? (ISP)
  • Am I tightly coupled to implementations? (DIP)

Closing thought

Most design issues don’t show up immediately.

They appear when systems evolve.

SOLID principles help you design not just for today, but for change over time.