Search code examples
javaphpoopstaticlate-binding

Is static late binding necessary to overload static variables?


A friend of mine asked me whether he can override a static variable in Java and I was shocked that he even thought about such a weird way of coding. Then he explained me that this is possible in PHP and I want to know whether there are a good reasons why a good developer should do that. In my opinion static members are characterized as class members and not related to an object and therefore they are not related to derivation of classes, but I cannot convince him as he is so naive and stubborn.

Can anyone give either a good argument against this whole thing or convince me that this is a cool feature?


Solution

  • The static inheritance does not make any sense. It is not that it is not possible, just that you get no benefit from it.

    With normal inheritance you get the benefit of having a different implementation for the same thing and not knowing/caring which implementation will be used. With static inheritance you don't have an object to operate with and you are using a class name, so you cannot take advantage of polymorphism.

    E.g. if you are calling Child.someMethod() you are tied to implementation of the child and if you actually just need the parent, you can just do Parent.someMethod() instead. If you need to add something to Parent implementation, you just make a Child.someOtherMethod() where you call the parent and do some other things after. The static inheritance is just syntactic sugar...