Iterative subpattern

The iterative subpattern allows sequential access to elements in an aggregation without exposing the inner representation of the aggregation. The aggregate of multiple objects is called an aggregate. An aggregate object is a container object that can contain a group of objects. The iteration subpattern encapsulates the iteration logic in a separate child object, separated from the aggregation itself. The iterative subpattern simplifies the aggregation interface. The iteration state of each iterator can be independent of each other. Iterative algorithms can be independent of aggregation role changes.

class Iterator;

class Aggregate
{
public:
    virtual Iterator *createIterator() = 0;
};

class Iterator
{
public:
    virtual void first() = 0;
    virtual void next() = 0;
    virtual bool isDone() = 0;
    virtual bool isDoneA() = 0;
    //virtual bool isDoneA() = 0;
};

class ConcreteAggregate :public Iterator
{
public:
    void first()
    {

    }
    void next()
    {
    }
    bool isDone()
    {

    }   
    virtual bool isDoneA()
    {

    }
};


int main12323I()
{

    cin.get();
    return 0;
}
Copy the code

The effect

It supports different ways of traversing an aggregate iterator simplifies the aggregation interface by allowing multiple traversals on the same aggregate

implementation

Who controls the iteration who defines the traversal algorithm how robust iterators are append iterator operations in C++ with multiple iterators an iterator has privileged access to an empty iterator used for conforming objects