Posts

Showing posts from March, 2022

SOLID Series: The Single Responsibility Principle

     I am starting a series about the SOLID Principles of Object-Oriented Design. These are five principles that you should keep in mind when designing an object-oriented program. They are coined by different authors in different moments in time. You can say that they are hard learned lessons from the past.     Today I am going to write about the first of the five principles - The Single Responsibility Principle . It was coined by Robert C. Martin, a.k.a. Uncle Bob. The narrative usually goes along the lines of: "The SRP means that a class should do just one thing". I want you to think very carefully about this. I want you to think about it because it's a lie!     Imagine what a program made of classes which do just one thing would look like! I've actually seen such a program. The claim was that it conforms to the SRP, but nothing could be further from the truth! I'll spare you the details and I'll show you only the code that illustrates the point. I