Question

E.g.

public abstract class Foo
{
    public Bar f1()
    {
        return new Bar();
    }
}

and

public class Bar extends Foo
{

}

From the design point of view, do you agree this design is anti-pattern?

Was it helpful?

Solution

Yes.

The reason it's bad is because it breaks encapsulation. If someone changes Foo, they realize they could be changing all subclasses. If someone changes Bar, they should never have to think about changing its super classes; its super classes should work the same regardless of the content of Bar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top