Wikipedia article on SOLID, the mnemonic acronym for five object-oriented design principles introduced by Robert C. Martin and named by Michael Feathers around 2004. These principles are foundational to NestJS’s architecture.
Key takeaways
- Single Responsibility Principle (SRP): A class should have only one reason to change — one responsibility. Improves maintainability, testability, and flexibility.
- Open-Closed Principle (OCP): Software entities should be open for extension but closed for modification. Enables adding features without changing existing code.
- Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types without altering program correctness. Ensures polymorphic behavior.
- Interface Segregation Principle (ISP): Clients should not depend on interfaces they don’t use. Reduces coupling and avoids unnecessary dependencies.
- Dependency Inversion Principle (DIP): Depend on abstractions, not concretions. This is the principle that NestJS’s entire dependency injection system is built upon.
Entities and concepts
- SOLID Principles
- Single Responsibility Principle
- Open-closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
- Robert C. Martin
Connections to existing knowledge
These principles are deeply embedded in NestJS’s design. Pipes embody SRP by separating validation logic from controller handlers. The NestJS module system with exports/imports follows OCP — modules are closed for modification but open for extension via the exports mechanism. NestJS’s dependency injection container is a direct implementation of DIP, where providers depend on abstractions (injection tokens) rather than concrete implementations. The FactoryProvider Pattern and Provider Definition Methods in NestJS Providers are practical applications of DIP.