SOLID Principles Cheatsheet

Want the PDF version? Click here to download S: Single Responsibility Principle (SRP) Real Meaning: One reason to change, not one “thing” it does. Why It Matters: Avoids “God classes” that block clean PRs & slow refactoring. Personal Analogy: “If you can’t give a clean commit message for the change, it’s violating SRP.” Code Smell: Method/class summary has multiple and/or. Actionable: Before adding a method, ask: “Is this a different concern?” Read more on SRP Short link: bytecrafted.dev/solid-srp O: Open/Closed Principle (OCP) Real Meaning: Add features by extension, not by editing old code. Why It Matters: Keeps legacy code stable; new business rules plug in cleanly. Personal Analogy: “If a new requirement means touching brittle switch statements, you’re not OCP.” Code Smell: Growing switch/if chains for types or behaviors. Actionable: When adding a rule, prefer new handler/class over changing the old one. Read more on OCP Short link: bytecrafted.dev/solid-ocp L: Liskov Substitution Principle (LSP) Real Meaning: Subtypes must behave as expected, no surprises for callers. Why It Matters: Swapping implementations shouldn’t break existing tests or runtime logic. Personal Analogy: “If a subclass throws where the base returns null, that’s an LSP landmine.” Code Smell: Derived classes override with different exceptions, parameters, or semantics. Actionable: Run parent class tests on every subclass; look for broken guarantees. Read more on LSP Short link: bytecrafted.dev/solid-lsp I: Interface Segregation Principle (ISP) Real Meaning: Small, client-focused interfaces, never force unused methods. Why It Matters: Reduces coupling, makes mocks/tests trivial, avoids NotSupportedException landmines. Personal Analogy: “If your interface summary needs bullet points, it’s already too fat.” Code Smell: Implementations with empty or throw NotSupportedException methods. Actionable: Extract groups of related methods into separate interfaces as soon as a client skips one. Read more on ISP Short link: bytecrafted.dev/solid-isp D: Dependency Inversion Principle (DIP) Real Meaning: Depend on abstractions, not concrete implementations, flip the usual control. Why It Matters: Makes business logic testable, swappable, and free of infrastructure glue. Personal Analogy: “If you see new SqlRepo() in a service, that’s DIP going up in flames.” Code Smell: Direct instantiation of dependencies inside business logic. Actionable: Use constructor injection for every external dependency; mock in tests, swap in production. Read more on DIP Short link: bytecrafted.dev/solid-dip Read full series: bytecrafted.dev/series/solid. ...

August 12, 2025 · 3 min

Refactoring Messy Code: My Approach to Coupling and Cohesion

TL;DR: High cohesion means classes focus on one job. Low coupling means classes don’t depend too much on each other. When I refactor messy code, these two principles guide every decision I make. Why I Focus on Cohesion and Coupling When Refactoring After 10+ years of building enterprise applications, I’ve inherited my fair share of messy codebases. The pattern is always the same: tangled classes doing too much, components that break when you touch something seemingly unrelated, and tests that require half the application to run. ...

August 4, 2025 · 7 min

Why Dependency Inversion Improves C# Code Quality

TL;DR DIP means depend on abstractions, not concrete implementations. Use interfaces and dependency injection to decouple business logic from details. DIP improves testability, flexibility, and maintainability in C# code. Avoid leaky abstractions, unnecessary interfaces, and service locator anti-patterns. Use C# 12 primary constructors and .NET 8 DI features for clean, modern architecture. The Dependency Inversion Principle helps you turn rigid, tightly-coupled code into flexible, testable systems. Rather than depending on concrete implementations, your high-level modules rely on abstractions. This goes beyond dependency injection, it’s about changing the direction of control flow. ...

July 25, 2025 · Last modified: August 7, 2025 · 13 min

Stop Forcing Unused Methods: Respect ISP

TL;DR ISP means interfaces should be small and focused on client needs. Avoid “God” interfaces that force clients to implement unused methods. Split large interfaces into cohesive, role-based interfaces. Use C# 12 features like default interface methods for flexibility. ISP improves maintainability, testability, and reduces coupling. Refactor fat interfaces by extracting related methods into separate interfaces. Interface Segregation Principle stops you from creating huge interfaces that force clients to implement methods they’ll never use. When interfaces get too big, your implementations end up filled with empty methods and unnecessary dependencies. ...

July 18, 2025 · Last modified: August 7, 2025 · 12 min

Prefer Interfaces Over Abstract Classes in C#: Build Flexible, Testable, and Maintainable Code

Learn why experienced C# developers choose interfaces over abstract classes 95% of the time. Real-world examples, team benefits, and clean architecture tips.

July 16, 2025 · 10 min

What the Square-Rectangle Problem Reveals About LSP

TL;DR LSP means you can use subtype objects anywhere you use base type objects without breaking code. Square/Rectangle inheritance that breaks existing code? That’s a classic LSP problem. Watch for subclasses that throw unexpected exceptions or silently change behavior. When behaviors are too different, reach for composition instead of inheritance. Make interfaces that clearly show what objects can and can’t do to avoid surprises. LSP violations often sneak past unit tests and show up as runtime bugs. The Liskov Substitution Principle isn’t just academic theory - it helps you avoid those “it worked yesterday” bugs that show up in production. When a subclass doesn’t behave like its parent promises, your code breaks in ways that unit tests often miss. ...

July 14, 2025 · Last modified: August 7, 2025 · 12 min

Dependency Inversion Principle in C#: Flexible Code with ASP.NET Core DI

Discover how the Dependency Inversion Principle makes your C# code flexible and testable. Learn to use ASP.NET Core DI to depend on abstractions, swap implementations, and build maintainable, scalable applications with real-world examples.

July 13, 2025 · 3 min

Use OCP Smartly - No Need for Plugin Overkill

TL;DR: The Open/Closed Principle (OCP) states: classes should be open for extension, but closed for modification. You don’t need to create a plugin for every new feature, favor simpler patterns like strategy, inheritance, or composition. Start with well-named abstractions; introduce extensibility points only when real change is expected. Keep code maintainable by balancing extension points with simplicity. Overengineering is a bigger risk than occasional refactoring. The Open/Closed Principle isn’t about making everything extensible. It simply means that your core business logic should be closed to modification but open to extension. The real skill is knowing when to apply it and when you’re just over-engineering your code. ...

July 11, 2025 · Last modified: August 7, 2025 · 10 min

Violating SOLID for Performance: When It’s Okay and How to Isolate It

Discover when it’s justified to break SOLID principles for performance in C#. Learn how to measure, isolate, and document exceptions, see real-world trade-offs, and keep your codebase maintainable, even in the engine bay of high-throughput systems.

July 10, 2025 · 10 min

What “One Reason to Change” Really Means in SRP

TL;DR: SRP means each class or module should have only one reason to change. Split validation, data access, and business logic into separate classes. SRP improves maintainability, testability, and scalability. Use C# 12 features like primary constructors and records for clean separation. Avoid “God” classes and mixing unrelated responsibilities. SRP is the foundation for applying other SOLID principles. Refactor large classes by extracting focused components and using dependency injection. The Single Responsibility Principle gets misunderstood more than any other SOLID principle. It’s not about doing one thing, it’s about having one reason to change. When your class changes for multiple business reasons, you’ve violated SRP and created a maintenance nightmare. ...

July 7, 2025 · Last modified: August 7, 2025 · 8 min
×