Page 1 of 1

Overriding access to methods

Posted: Fri Aug 07, 2009 10:51 am
by ConvertFromOldNGs
by cdshearer >> Thu, 14 Mar 2002 20:44:07 GMT

Hi All

I'd be interested in opinions on this idea...

It would be nice if I could reimplement a public method on a subclass change its access to protected so that clients couldn't call the method. Other languages, such as Java have this feature.

There are quite a few methods in JADE which are public that really don't represent the public interface to the class. For example, the userNotification and sysNotification methods probably shouldn't be public. Another example is event methods on controls and forms.

There would obviously be issues such as polymorphic calls to an object's methods, but runtime exceptions could be raised for these.

I know that I can stop clients calling methods by reimplementing them and raising an exception when they are called, but changing their access would be a nicer option.

Craig

Re: Overriding access to methods

Posted: Fri Aug 07, 2009 10:51 am
by ConvertFromOldNGs
by JensRichnow >> Mon, 15 Jul 2002 23:21:23 GMT

Yes, I would like to see such a feature where the signature of the overriden method can be changed to a different access modifier.

However, as far as I remember, the overriden method can be declared more public and not more private in Java. This is the opposite of what you are trying to achieve.

Designing the system to use top-level, possible abstract super classes (API design) would hide the imlementation of subclasses. However, this might not be possible in all cases.

If we talk overriding of methods what about overloading (which I find useful in Java)?