Вопрос

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