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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 changesBar, they should never have to think about changing its super classes; its super classes should work the same regardless of the content ofBar.