Which inheritance makes more sense :
class SequentialIterator{
SequentialIterator next();
};
class RandomAccessIterator : public SequentialIterator{
RandomAccessIterator shift( int del );
};
or
class RandomAccessIterator {
RandomAccessIterator shift( int del );
};
class SequentialIterator : public RandomAccessIterator{
SequentialIterator next();
};
If I say “the derived class gives more complicated functionality than the base class” (first of all does this statement even make sense here), which is the more basic operation : next or shift?
EDIT : I’m actually designing interfaces for number sequences.
I think you’re looking at this from the wrong direction. In your first code-snippet, you essentially have three methods:
In your second, you also have three methods, but they’re not the same ones:
Looked at in this way, I think it should be clear that only the first version makes sense: a
RandomAccessIteratorclass can reasonably offer anext()method, but aSequentialIteratorclass cannot reasonably offer ashift(int)method.(This is assuming, of course, that there’s some reason to have one of them inherit from the other to begin with.)