Is this cheating?

Discussion in 'Plugin Development' started by gamerguy14, Aug 22, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    gamerguy14

    Is it cheating or bad coding to subclass an object just so you can call a protected method on objects of the super type.

    For example:

    You have class A:

    Code:
    public class A {
     
        protected void someProtectedMethod() {
            System.out.println("I am protected");//Just to have some code in it but it is irrelevant.
        }
    }
    Then class B:

    Code:
    public class B extends A {
     
        public static void callProtectedMethod(A a) {
            a.someProtectedMethod();
        }
    }
    Is there anything wrong with doing this?
     
  2. Offline

    NSArray

    There is nothing wrong with doing that in the right cases. It's all about the ultimate goal of you code, and the best way of implementing it. With only that price of code it's impossible to tell if it's right or wrong. You'd need to look at the whole class and decide form there.

    The point of protected methods is to allow subclasses to use them while restricting access from other classes.
     
  3. Offline

    skore87

Thread Status:
Not open for further replies.

Share This Page