The governing principles of SOLID programming
As we stated in the last section, there are five underlining principles that govern SOLID programming. They are as follows:
- S: Single-responsibility principle (SRP)
- O: Open-closed principle (OCP)
- L: Liskov substitution principle (LSP)
- I: Interface segregation principle (ISP)
- D: Dependency inversion principle (DIP)
The first, and in my opinion, the easiest and most important principle to explore is the SRP.
The single-responsibility principle
The SRP is, in my opinion, the most important of the five principles to implement. In short, the SRP states that a code module should do one thing and one thing alone, kind of like the way we defined what a function should do in Chapter 5. In short, this goes back to the one-sentence rule. If you have to use the word and to describe your module, you have violated the SRP and you should break the service out. Generally, this is a trick that many experienced developers...