I have to iterate over specific points of perimeter rectangle (in some cases I need to iterate over one line of this rectangle, In other cases I need to iterate over entire rectangle). I have an interface PointIterator.
struct Point
{
double x,y
}
class PointIteratorI
{
virtual void next() =0;
virtual void isOver() =0;
virtual Point& getPoint() = 0;
}
in case of iterating over one line
class LineIterator:public PointIterator
{
....
}
in case of iterating over rectangle's perimeter
class PerimeterIterator:public PointIterator
{
....
}
In case of LineIterator I also need the type of line (horizontal or vertical, the rectangle have 2 horizontal and 2 vertical lines). But interface like "getLineType" is wierd for LineIterator type. It seems like this method is not for this class. Because in such a case the class LineIterator will be responsible for iterating and direction. It's breaking Single-responsiblity principle.
I thought for different Interface like:
class LineObjectI
{
public:
virtual LineType getLineType() = 0;
.....
}
class LineIterator:public PointIterator, public LineObjectI
{
protected:
virtual LineType getLineType() = 0;
....
}
for hiding this interface. I want to know is there a better way to do to check type of line on LineIterator.