I have class A, with methods foo and bar, that are implemented by A1 and A2. The functionality in both A1 and A2 is the same. In other words:
public class A {
public int foo() { return 0; };
public int bar() { return 1; };
}
class A1 extends A {
public int AnotherFooFunction() { return foo(); }
public int AnotherBarFunction() { return bar(); }
}
class A2 extends A {
public int AnotherFooFunction() { return foo(); }
public int AnotherBarFunction() { return bar(); }
}
Is it better to keep the code in this fashion, or to swap out those virtual methods as static methods? (In Java, everything non-final/non-private is considered virtual, right?)
According to the Designing for Performance section in the Android Developer Docs, I should swap out these virtual methods for static ones. So the above becomes:
public class A {
public int foo() { return 0; };
public int bar() { return 1; };
}
class A1 extends A {
public int AnotherFooFunction() { return A.foo(); }
public int AnotherBarFunction() { return A.bar(); }
}
class A2 extends A {
public int AnotherFooFunction() { return A.foo(); }
public int AnotherBarFunction() { return A.bar(); }
}
Is this how it "ought" to be? I fully realize that I may be misinterpreting this paragraph in the docs.