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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top