Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

Improve code readability by refactoring if blocks to dedicated classes

Original – by Freek Van der Herten – 1 minute read

If you code bases contains a long procedure with a lot of if statements to determine which case should be handle, consider extracting each case to its own dedicated class. Here's an example from the Mailcoach code base.

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

What are your thoughts on "Improve code readability by refactoring if blocks to dedicated classes"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.

Webmentions

Fazlul Kabir liked on 1st June 2021
Ahmed Nagi retweeted on 1st June 2021
Ahmed Nagi liked on 1st June 2021
Peter Brinck 🤘 liked on 1st June 2021
Marko Rsumovic liked on 1st June 2021
José Cage liked on 1st June 2021
Rich liked on 1st June 2021
Daniele Esposito liked on 1st June 2021
Arthur Weill liked on 31st May 2021
Ahmet Mirzabeyoğlu retweeted on 31st May 2021
Spatie retweeted on 31st May 2021
Burhan liked on 31st May 2021
Ahmet Mirzabeyoğlu liked on 31st May 2021
Yannick Yayo liked on 31st May 2021
Scorp974 liked on 31st May 2021
Parthasarathi G K liked on 31st May 2021
Ali Mahdavi liked on 31st May 2021
Vargas Josue liked on 31st May 2021
Vargas Josue retweeted on 31st May 2021
Wyatt liked on 31st May 2021
ángel retweeted on 31st May 2021
Nathanael McDaniel 🖥 liked on 31st May 2021
ángel liked on 31st May 2021
Kamau Wanyee liked on 31st May 2021
Fabrizio replied on 31st May 2021
We need more sauce like this 🙌
Padam Shankhadev liked on 31st May 2021
Oilmone liked on 31st May 2021
ダビッド トレス liked on 31st May 2021
Willan Correia liked on 31st May 2021
K. liked on 31st May 2021
이현석 Hyunseok Lee liked on 31st May 2021
jagcgc373 liked on 31st May 2021
Franck Mercado liked on 31st May 2021
Elliot Derhay replied on 31st May 2021
Thanks for the reminder about the Factory pattern. I just remembered I have some code I can use that for. 🙂
Podcaster Dev replied on 31st May 2021
I have long since held that the most powerful insight into OO programming is that it all basically resolves down to encapsulating if/switch logic ...
Sébastien A retweeted on 31st May 2021
/dev/prabakaran retweeted on 31st May 2021
Matthew Campbell liked on 31st May 2021
Fabrizio liked on 31st May 2021
Mike liked on 31st May 2021
/dev/prabakaran liked on 31st May 2021
Elliot Derhay liked on 31st May 2021
Podcaster Dev liked on 31st May 2021
Mark Topper liked on 31st May 2021
Tim Nelke liked on 31st May 2021