InvisibleAbstractMethod

From APIDesign

Revision as of 23:26, 9 March 2012 by JaroslavTulach (Talk | contribs)
Jump to: navigation, search

Having an abstract class with package private abstract method effectively prevents anyone to subclass it. That can be considered as good API design pattern, especially if that is something one starts with.

However it can also turn into a huge anti-pattern. Adding first package private abstract method into an abstract class is in fact an incompatible change. If the class used to be subclassable before, this prevents the subclassing and as such classes that used to compile may compile no longer.

The hidden catch is that tools like Sigtest are unlikely to catch this situation, as they don't care about package private methods! Some people complained about unnecesary complexity of various OOP access modifiers - and they were likely right, but this case worse (from the point of an API designer) - a change to an implementation detail may change the published APIs!

TBD

Personal tools
buy