## Advanced Topic 26.1

Generic Programming with Inheritance and Templates

- Design Patterns further recommends using an abstract base class for the iterator and the aggregate
- Generic code can then be written:

  >     void print_all(AbstractAggregate* items)
  >     {
  >        AbstractIterator* iter = items->create_iterator();
  >        while (!iter->is_done())
  >        {
  >           cout << iter->current_item() << "\n";
  >           iter->next();
  >        }
  >     }

prev |top |next