Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tomas Votruba:
Collector Pattern for Dummies
Jun 15, 2018 @ 14:03:13

In a new post to his site Tomas Votruba comes back to a topic he posted about previously - the collector pattern - and provides a simpler, more introductory look at the pattern and what it's useful for.

I wrote Why is Collector Pattern so Awesome a while ago, but I got feeling and feedback that it's way too complicated.

The pattern itself is simple but put in framework context, it might be too confusing to understand. That's why we look on collector pattern in minimalistic plain PHP way today.

He uses a calculator example help explain the use of the pattern, starting with a simple class that calculates the price of a product + VAT. He then shows a few examples of how it could grow over time as business requirements change. He refactors the class to make it easier to add in these one-off changes by setting them all as "calculators' in a calculator collection. He provides the code examples for this refactor and an example of it in use.

tagged: collector pattern introduction calculator tutorial

Link: https://www.tomasvotruba.cz/blog/2018/06/14/collector-pattern-for-dummies/


Trending Topics: