Questions and answers
- Do the SOLID principles only apply to OO code?
No. Although originally applied to an OO context, they have uses in both functional programming and microservice design. SRP is almost universally useful—sticking to one main focus is helpful for anything, even paragraphs of documentation. SRP thinking also helps us write a pure function that does only one thing and a test that does only one thing. DIP and OCP are easily done in functional contexts by passing in the dependency as a pure function, as we do with Java lambdas. SOLID as a whole gives a set of goals for managing coupling and cohesion among any kind of software components.
- Do we have to use SOLID principles with TDD?
No. TDD works by defining the outcomes and public interface of a software component. How we implement that component is irrelevant to a TDD test, but using principles such as SRP and DIP makes it much easier to write tests against that code by giving us the...