Skip to content

TriangularDependence test

Artyom Lobanov edited this page Jul 11, 2017 · 1 revision

Checks that algorithms take into account global dependencies. In this situation ClassB.methodToMove and ClassC.methodToMove depends on each other, and both depends on ClassA.method. If you see only ClassB.methodToMove you can't know to which class (ClassA or ClassC) you should better move it.

Expected refactorings
Member Move to
ClassB.methodToMove ClassA
ClassC.methodToMove ClassA
package triangularDependence;

public class ClassA {
    static void method() {
        Integer.parseInt("9");
    }

    void foo1() {
        method();
        foo3();
    }

    void foo2() {
        method();
        foo1();
    }

    void foo3() {
        method();
        foo2();
    }
}
package triangularDependence;

public class ClassB {

    static void methodToMove() {
        ClassA.method();
        ClassA.method();
        ClassA.method();
        ClassA.method();
        ClassC.methodToMove();
        ClassC.methodToMove();
        ClassC.methodToMove();
        ClassC.methodToMove();
    }

    static void foo() {}
}
package triangularDependence;

public class ClassC {

    static void methodToMove() {
        ClassA.method();
        ClassA.method();
        ClassA.method();
        ClassA.method();
        ClassB.methodToMove();
        ClassB.methodToMove();
        ClassB.methodToMove();
        ClassB.methodToMove();
    }

    static void foo() {}
}