Originally Posted by
Mario F.
Well, dunno Elysia.
The problem (not really a problem, mind you) is that an iterator class only makes sense in the presence of an aggregator class. The moment you try to protect aggregate functionality from the main class, your iterator becomes unintuitive. Personally, as a user of your class, I'd rather see it implementing it's own traversing functionality.
Of course it is all a matter of design. It's your choice what you want to do. Being that you still would want an iterator class, in order to better protect yourself from future changes, I'd probably partition your stream class roles with a mixin interface class that implemented the aggregate functionality of your stream class. Then, implement the iterator pattern from that aggregate.
If this is not an option because the stream class will always be used with a buffer, you'll probably be forced to indeed derive your iterator from the stream class. But that's really perverting the idea of a derived class. In any case, you are probably looking into a private inheritance with protected members in the stream class.
Really, I'd go back to anon initial post and suggest you consider your design. If I was to use your stream class, i'd be slightly annoyed if I had to go through an iterator to traverse what is essentially a non aggregate.