Category: PHP

If you want to skill up your knowledge of programming (not only in PHP but in general) learning design patterns is incredibly useful. The Strategy pattern that we are going to see in this article is one if not, the simplest design pattern you can learn.

As you may have understood this is not a class but rather an interface and what it does is to provide the getPercentageSale() method to the classes that implement it.

A thought that I had the first time I saw this and you might have right now is why we have complicated the code so much and created these other classes and relationships. The reason is that we now have multiple strategies (or behaviours) that do not conflict with each other because of their vertical relationship and that can be used to compose the type of Shirt that we want.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners