Re: Best way to develop in parallel



Brian wrote:
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.

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() ); }
.



Relevant Pages

  • Re: Cant a class extends a abstract class and implements a interface at once??
    ... Constructors are not methods, they cannot be inherited (but you can ... to have them just because they are not going to be called by "super" ... void) with the same name as the interface. ...
    (comp.lang.java.programmer)
  • Re: writing drivers using C++
    ... declaration will lead to a subroutine invocation. ... Whether a class has overloaded operators is part of ... the interface of that class, ... Without using classes whose constructors allocate ressources in need ...
    (comp.os.linux.development.system)
  • Re: virtual inheritance nightmare
    ... But it _might_ be used if you derive from Interface and make that class ... > virtual void DoThing() ... The work-around here is to declare 'Interface*' constructors ...
    (comp.lang.cpp)
  • Re: writing drivers using C++
    ... Whether a class has overloaded operators is part of ... the interface of that class, ... 'cleanup code' can often be avoided (eg by allocating ... temporary buffers of any kind on the stack, which constructors cannot ...
    (comp.os.linux.development.system)
  • Re: Benefits of Protected Construtors in MFC
    ... I want to ask you about logic behind the protected constructors in MFC. ... virtual void Dumpconst; ... CMultiDocTemplate * GreenTemplate; ... cannot be used already in either a string, icon, or menu context. ...
    (microsoft.public.vc.mfc)