Let's say I have an abstract parent class called "shape", and that there are multiple subclasses (triangle, square, circle... ). I want to define an abstract method in the parent "shape" class which all subclasses must implement, let's call it "draw". So all shape subclasses must provide the "draw()" method. But, the draw method takes a parameter of type "Stencil", and, not every shape subclass can use just any stencil...
So there is one abstract "shape" class, multiple shape subclasses, and multiple stencils. I need a draw method defined in the shape class. A square might use Stencil1 and the circle might use Stencil2.
I'm guessing that generics would do the trick, but I'm not sure. Each shape subclass needs to define the draw method with a specific stencil because these classes are used by other classes as well, and the compiler should force all programmers to call the draw methods with the stencil that is supported by that class. We can't define an abstract method like "public abstract void draw(Stencil s)" because then the programmer could pass in any stencil to the square class, whereas the square class only supports "Stencil1"
Any ideas?
Update1: Should add that the shape class doesn't care which stencil is used by the subclass, but since the subclasses are used in other classes too, it's important that the draw method is defined so that only the supported stencil is accepted by the compiler.