Note that there are some explanatory texts on larger screens.

plurals
  1. POChange classes in Java
    text
    copied!<p>I have a class ImageA, and a class ImageB. The both classes represents an image in my app, but each one in a different way. Even being different, their constructors are equal, and both have the method <strong>compare</strong>.</p> <p>So, what I done was creating a class Image, and ImageA and ImageB are subClasses of Image.</p> <pre><code>public abstract class Image { protected String path; public Image(String path){ this.path = path; } public abstract double compare(Image i2); } public class ImageA extends Image{...} public class ImageB extends Image{...} </code></pre> <p>But what I need is to test each implementation of image (ImageA and ImageB, in this case), to see the best one.</p> <p>Is there a way to do this, changing my code at minimum? Suppose the objects used are from ImageA class, and I want to test now imageB class;</p> <p>Obs.: </p> <ul> <li><p>If all imageA objects of my app are setted by the type (ImageA i = new ImageA()), I'd have to change manually all in the code.</p></li> <li><p>But even if I use the superType and cast it (Image i = (ImageA)new Image()), I'll have the same problem, to change the casts.</p></li> <li><p>My question is different from this one: <a href="https://stackoverflow.com/questions/1456629/refactoring-abstract-java-class-with-many-child-classes">Refactoring abstract Java class with many child classes</a> . In my case, the attributes inside the child classes are different, and I keep the attributes common to these classes in the Image class.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload