AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() What other principles the SRP is based on?.Let’s ask these questions, and try to find the answers: This is one of the reasons I would like to speak with you about the SRP. This is how I experienced first hand the Single Responsibility Principle, and, since then, I saw many beginners trying to do the same. Exactly the contrary of what you would expect from the SRP! ![]() It was difficult to understand, difficult to scale, and difficult to maintain. This project became a mess of classes all coupled to each other. I felt like I was following the path of the Giants, the Evangelists, the Words of the Gods themselves. I fragmented my Shipment class, creating many more classes with one method each: everything was light, teared apart, shredded. All these responsibilities in the same class! What I was thinking? What will change? I wasn’t sure, but every single method looked like they could have one reason to change. What’s a reason to change for the Shipment class? Well, maybe our client, who asked us to build an e-commerce, will want to change the Shipment class at one point? When I came back to work the following Monday, I looked at the PHP classes I was working on. “If a class has only one reason to change, it’s nicer! It’s small, it’s light, it’s great! I understand development!” Like this class which represent an animal in this article, or this Circle class in another article, or this Spaceship (?) class in this blog post. What did I find? My classes should only have one reason to change. What’s a responsibility? I was asking myself, my mouth full of muesli, a Sunday morning, while sloppily browsing The Internet. ![]() ![]() The SRP looked like a magic spell I could cast for my code to be instantaneously better. The senior developers, the chosen ones, were calling it the Single Responsibility Principle, or SRP. Once upon a time, at the beginning of my journey as a professional developer, I quickly heard about the principle which will save us all, part of the Sacred SOLID principles. , updated Twitter #Fundamentals #Architecture The Single Responsibility Principle Revisited ![]()
0 Comments
Read More
Leave a Reply. |