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

StarTutorial.com:
Understanding Design Patterns - Iterator
May 30, 2018 @ 15:25:33

The StarTutorial.com site has posted the next in its series covering the definition and use of design patterns in PHP applications. In this latest tutorial they cover the Iterator pattern.

[The Iterator pattern] provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

Much like the previous parts of the series, they set up a sample situation to show how the code could be created and how it can be refactored to use the design pattern. In this case, it's an example of women's versus men's products and the fact that they store their inventory differently behind the scenes. The initial code tries to manually merge these two lists by getting the names from each. This is then refactored to define the product types as iterators and pulling the information using a unified interface.

tagged: designpattern iterator introduction tutorial

Link: https://www.startutorial.com/articles/view/understanding-design-patterns-iterator


Trending Topics: