Writing SOLID code
SOLID is an acronym introduced by Michael Feathers summarizing the words of Robert C. Martin. The intent of SOLID is to provide developers with a set of principles that will guide them toward more maintainable code that resists becoming technical debt.
The five principles of SOLID code are:
- Single Responsibility Principle (SRP)
- Open-Closed Principle (OCP)
- Liskov Substitution Principle (LSP)
- Interface Segregation Principle (ISP)
- Dependency Inversion Principle (DIP)
In this section, we’ll cover all five of these principles.
Single Responsibility Principle
The Single Responsibility Principle (SRP) says that a class should be responsible for one thing and one thing only. Here are a few examples of classes that follow the SRP:
- A class responsible for saving application data to a specific file format
- A database access class dedicated to executing queries against a database table or set of tables
- An API controller...