Replace Conditional with Polymorphism
Polymorphism is an extremely helpful technique to master. Take a look at this article to see it implemented in a Laravel application:
If you've ever done any research into refactoring, or programming in general, you've most likely heard the term "polymorphism". When I first came across it, I have to admit, I was intimidated.
Now that I've become more familiar with the concept, I can assure you, the word itself is more complicated than the underlying principle!
Refactoring Techniques: Extract Method
A while back, I’d thrown out a question in the Laravel Slack channel asking people what the “must-reads” were for devs. Along with the obvious Uncle Bob books, someone (I believe it was Matt Stauffer) mentioned Refactoring - Improving the Design of Existing Code by Martin Fowler. I looked it up on Amazon and while it was available, I found myself questioning whether a book that was dated 1999 would have any validity in the “modern” coding world I find myself in… not to mention that it didn’t appear to be written for PHP, which is the primary language I use.
I’m glad to say that I put aside my doubts, followed the recommendation, and picked up a copy!
Initially I was disappointed to see that the examples are written in Java, a language I know nothing about. However, I’ve been surprised to see how the broader concepts, such as organization and classes, relate very similarly to what I find myself dealing with in the PHP/Laravel world.
Page 2 of 2 (12 total entries)