Design Patterns PHP - Iterator Java

1) What have we got?

We have some "Collection" class which has some collection of elements.


class Collection
{
    /**
     * @var string[]
     */
    private $elements = [];

    function __construct()
    {
    }

    public function addElement($string)
    {
        $this->elements[] = $string;

        return $this;
    }

    public function removeElement($string)
    {
        if (isset($this->elements[$string]))
            unset($this->elements[$string]);
    }

    /**
     * @return \string[]
     */
    public function getElements()
    {
        return $this->elements;
    }

    public function getCount()
    {
        return count($this->elements);
    }

}




2) What is our goal?

We would like to client allow traversing elements but we don't want to give him access to inner structure(elements).