A
A
anna_makeenko2019-12-28 21:59:21
PHP
anna_makeenko, 2019-12-28 21:59:21

How to properly process a collection?

There is a collection of objects, for example:

class Object
{
    protected $name
    protected $status;
}

class ObjectCollection
{
    protected $items = [];
//...
}

You need to write a checker that will perform some checks on objects and change their status. How best to implement?
$collection = new ObjectCollection();

$collection->add(new Object());
$collection->add(new Object());

//...

$checker = new Checker();

$collection = $checker->process($collection);

In this case, the method returns the modified collection. Is this correct from a design point of view? Are there ways to do better? Maybe there are implementation examples on GitHub?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question