Simple Trick to Improve Your Classes in PHP
My secret trick how to code better. See how to make your classes better and avoid having too many responsibilities.
At the moment of writing, there are about 6500 articles on Medium mentioning the Single Responsibility Principle. Written mostly by people who don’t know what this rule is exactly about.
There are already some best articles on the topic, written by the most influential people in the coding industry. I will reference these articles at the bottom of this publication. Today though, I will do my best to avoid the theory and stick to real-life example.
Are you familiar with the Rubberducking technique? In theory, by articulating the problem to a duck (be it imaginary or real if you insist) you often come up with the solution in the process of speaking everything aloud.
This is the trick I use when designing new functionalities. I ask the duck on my desk questions about the code I’m trying to write. The main question that assists me in writing decoupled code is:
If was to write more implementations of…