SOLID Principles
Five foundational OOP design principles for writing clean, maintainable, and extensible object-oriented software.
Single Responsibility Principle
A class should have only one reason to change. Each class owns a single, well-defined responsibility.
Rule: If you have to say "and" to describe what a class does, it has more than one responsibility. Split it.
Open/Closed Principle
Open for extension, closed for modification. Add new behavior via new classes, not by editing existing ones.
Rule: New behavior should be added by writing new code, not by changing working code that is already tested.
Liskov Substitution Principle
A subtype must be fully substitutable for its base type. Callers should not notice when a subclass is used in place of a parent.
Rule: If you must check the concrete type before calling a method, your hierarchy violates LSP. Model behavior, not identity.
Interface Segregation Principle
No client should be forced to depend on methods it doesn't use. Prefer many small, focused interfaces over one large general-purpose one.
Rule: A class that implements a method just to throw NotImplementedException is a clear signal that the interface is too fat.
Dependency Inversion Principle
Depend on abstractions, not on concretions. High-level modules should not import low-level modules directly.
Rule: Inject dependencies via constructor or interface. If swapping a database requires changing business logic, DIP is being violated.