Roadmap › 1. .NET › Step 11
SO

SOLID Principles with Examples

The five SOLID principles with bad-vs-good C# code, plus DRY, KISS, YAGNI, dependency injection and how SOLID shows up in ASP.NET Core.
What it is & where it is used

SOLID is five object-oriented design principles that make code easier to change, test and extend. The acronym was coined by Michael Feathers around 2004 for principles collected by Robert C. Martin ("Uncle Bob") in the late 1990s and early 2000s.

LetterPrincipleOne-line meaning
SSingle ResponsibilityA class should have one reason to change
OOpen/ClosedOpen for extension, closed for modification
LLiskov SubstitutionSubtypes must be usable wherever the base type is expected
IInterface SegregationMany small, specific interfaces beat one fat interface
DDependency InversionDepend on abstractions, not concrete classes

Interviewers almost always ask you to explain each with an example and then show where you applied it.

Versions & history
YearMilestone
1987Barbara Liskov presents the substitution idea (keynote "Data Abstraction and Hierarchy"); formalised with Jeannette Wing in 1994
1988Bertrand Meyer defines the Open/Closed Principle in Object-Oriented Software Construction
1996–2000Robert C. Martin publishes articles on OCP, LSP, DIP, ISP; paper "Design Principles and Design Patterns" (2000)
~2004Michael Feathers arranges them into the acronym SOLID
2002 / 2006Agile Software Development: Principles, Patterns, and Practices (and the C# edition, 2006)
2017Clean Architecture restates SRP as "a module should be responsible to one actor"
Lifecycle

How SOLID is applied during development:

  1. Design — split responsibilities (SRP), define interfaces around what consumers need (ISP, DIP).
  2. Implement — inject dependencies through constructors; keep classes small.
  3. Extend — add behaviour by adding new classes (OCP) rather than editing switches.
  4. Test — mock the abstractions; unit-test each class in isolation.
  5. Review — code review checks for god classes, new of services inside business logic, and subclasses that throw NotSupportedException (LSP smell).
  6. Refactor — when a class keeps changing for unrelated reasons, split it.
Tools used to develop
  • ASP.NET Core DI container (Microsoft.Extensions.DependencyInjection) — DIP in practice.
  • Scrutor — assembly scanning and decorators for the built-in container.
  • Autofac — advanced DI container.
  • xUnit + Moq / NSubstitute / FakeItEasy — mocking abstractions.
  • SonarQube / SonarLint, NDepend, Visual Studio code metrics — find large classes, high coupling, complexity.
  • ArchUnitNET / NetArchTest — enforce layering rules in tests.