java - Is it possible to have specialized parameters in overridden methods? -


Let me assume that I have an abstract basic class called "figure", and that there are many sub-classes (triangle, square, circle). ..) I want to define an abstract method in the parent "shape" class which should implement all the subclasses, let's call it "draw" so sub-classes of all sizes should be given the "draw ()" method . However, the type of draw pattern takes a parameter of type "stencil", and every shape subclass can not use any stencil ...

Therefore an abstract "shape" class, multiple shape subclass , And multiple stencils I need to draw the defined in the shape class. One square can use stencil 1 and circle circle can be used.

I think a generic move will be done, but I'm not sure. The sub-classes of each size need to define the draw pattern with a specific stencil, because these sections are also used by other classes, and the compiler with all the programmers have the draw methods with the stencil supported by that class. Must be forced to call. We can not define an abstract method such as "public best view draw (stencil s)" because then the programmer can pass in a stencil in square square, while square squares only support "stencil 1"

Any thoughts?

Update1: It should be added that the shape class does not care which subclass is used by the stencil, but because subclasses are also used in other classes , It is important that the Draw method is defined so that only supported stencils can be accepted by the compiler.

  public abstract class size & lt; S stencil expands & gt; {Public essence zero zero (s stencil); } Public square Square size and lieutenant; Stencil 1 & gt; {Public Zero Draw (Stencil 1 Stencil) {stencil.letsdo (); Stencil.some (); Stencil.drawing (); }} Public square circle size and lieutenant; Stencil 2 & gt; {Public Zero Draw (Stencil 2 Stencil) {stencil.some ()) stencil.more (); Stencil.drawing (); }}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -