Skip to main content

How evil would it be to enforce direct subclasses only?

Posted by timboudreau on May 1, 2009 at 11:43 AM PDT
Every now and then I get tempted to do this:
public abstract class AbstractType {
    protected AbstractType() {
        if (getClass().getSuperclass() != AbstractType.class) {
            throw new AbuseOfInheritanceError();
        }
    }
}

I've seen so much code that was made less readable and more complicated by overuse of inheritance; there are cases where it would be doing the world a favor.

However, probably it would just make people want to shoot me.

sunsetFlyingWithPavel.png
Related Topics >>

Comments

I sent a out of time Coin proposal to limit extension and implementation of interfaces outside a package. That's even more fascist.