Hi -
I have MyPossiblyFlawedClass and MyOtherPossibilyFlawedClass.
Both have exactly the same method signatures, constructors,
etc.
They solve a number crunching problem using two different
algorithms and they're being used to discover flaws in the
other. How can I easily switch between the classes? I'm
doing it now with an import mypath.classA/classB statement.
But this is getting a bit out of control. I'm constantly
switching four import statements many times a day.
Thanks for any ideas.
Brian
Alan Krueger - 29 Jun 2005 01:14 GMT
> I have MyPossiblyFlawedClass and MyOtherPossibilyFlawedClass.
> Both have exactly the same method signatures, constructors,
[quoted text clipped - 7 lines]
> But this is getting a bit out of control. I'm constantly
> switching four import statements many times a day.
Move their common methods into an interface and have each of them
implement it. Import them both. Have the test code refer to the
interface and construct one or the other based on some condition.
interface A
{
void foo();
}
class B implements A
{
void foo() { System.out.println( "B.foo" ); }
}
class C implements A
{
void foo() { System.out.println( "C.foo" ); }
}
void testA( A a ) { a.foo(); }
void testB() { test( new B() ); }
void testC() { test( new C() ); }