B
bfeist
I'm working on a maze generation program which works with MazeCell
objects describing the geometry and topology of individual cells of a
maze -- how they connect and how to draw them. MazeCell itself is an
abstract class, which will have concrete classes of IsoscelesTriangle,
Hexagon, RightTriangle, and Square (for instance). Now, it turns out
that there is a subclass of RightTriangle which is topologically
equivalent to IsoscelesTriangle, meaning that the "neighbors" of each
cell are identical: if the triangle points upward, its neighbors are to
the left, to the right, and down in the same way for both of them; this
is not true for other subclasses of right triangle.
I'd like to reuse code for the RightTriangle subclass and
IsoscelesTriangle subclasses, but it's not clear to me what the best
way of doing so is. Certainly neither IS-A the other. I suppose I
could stick the method in MazeCell itself, or in an intermediate new
class called TriangleCell which extends to both RightTriangle and
IsoscelesTriangle, but since the method really isn't general for all
subclasses in the sub-hierarchy that doesn't seem appropriate.
The cleanest alternative might be to separate out classes defining
geometry (how it's drawn) from topology (how they're connected), but
that seems complicated.
Any suggestions?
Thanks,
Bruce Feist
objects describing the geometry and topology of individual cells of a
maze -- how they connect and how to draw them. MazeCell itself is an
abstract class, which will have concrete classes of IsoscelesTriangle,
Hexagon, RightTriangle, and Square (for instance). Now, it turns out
that there is a subclass of RightTriangle which is topologically
equivalent to IsoscelesTriangle, meaning that the "neighbors" of each
cell are identical: if the triangle points upward, its neighbors are to
the left, to the right, and down in the same way for both of them; this
is not true for other subclasses of right triangle.
I'd like to reuse code for the RightTriangle subclass and
IsoscelesTriangle subclasses, but it's not clear to me what the best
way of doing so is. Certainly neither IS-A the other. I suppose I
could stick the method in MazeCell itself, or in an intermediate new
class called TriangleCell which extends to both RightTriangle and
IsoscelesTriangle, but since the method really isn't general for all
subclasses in the sub-hierarchy that doesn't seem appropriate.
The cleanest alternative might be to separate out classes defining
geometry (how it's drawn) from topology (how they're connected), but
that seems complicated.
Any suggestions?
Thanks,
Bruce Feist