Echtzeitsysteme / java-refactoring-ttc

Object-oriented Refactoring of Java Programs using Graph Transformation (TTC'2015)
0 stars 0 forks source link

Why should hidden_pum1_1 fail? #24

Closed tsdh closed 9 years ago

tsdh commented 9 years ago

This refactoring tries applyPullUpMethod(hidden.program.one.ParentClass, method).

ParentClass has two subclasses:

// ChildClass1.java
public class ChildClass1 extends ParentClass {
    String field = "I am a field";

    public static void main(String[] args) {
        ChildClass1 c = new ChildClass1();
        System.out.println("Field: "+c.field);
        System.out.print("Method: ");
        c.method();
    }

    public void method(){
        System.out.println("Hello World!");
    }
}
// ChildClass2.java
public class ChildClass2 extends ParentClass {
    public void method(){
        System.out.println("Hello World!"+"I am a field");
    }
}

There is no way for a solution to see that these two method() definitions aren't equivalent. They both have the same signature and access only the same method PrintStream.println(). So to my best understanding, method() is pullable.

SvenPeldszus commented 9 years ago

Oh sorry, in my version the program looks a bit different. I've pushed the wrong version.

It should be:

// ChildClass1.java
public class ChildClass1 extends ParentClass {
    String field = "I am a field";

    public static void main(String[] args) {
        ChildClass1 c = new ChildClass1();
        System.out.println("Field: "+c.field);
        System.out.print("Method: ");
        c.method();
    }

    public void method(){
        System.out.println("Hello World!"+c);
    }
}
// ChildClass2.java
public class ChildClass2 extends ParentClass {
    public void method(){
        System.out.println("Hello World!"+"I am a field");
    }
}

The field access got lost.

tsdh commented 9 years ago

Ok, then it makes sense.

SvenPeldszus commented 9 years ago

Does this case now work as expected?

tsdh commented 9 years ago

Yes, so I'm closing this issue.