我的意思是:为什么在bean中创建受保护的属性被认为是一种不好的做法?
public class SomeBackingBean {
protected String someString;
public void setSomeString (String str) {
this.someString = str;
}
public String getSomeString {
return someString;
}
}
这只是一个笼统的回答一般情况下。
现在第二个例子:
public abstract class AbstractBean<T extends EntityInterface> {
protected T entity;
public void setEntity (T t) {
this.entity = t;
}
public void getEntity() {
return entity;
}
protected ReturnType calculateSomethingCommon() {
//use entity (knowing that it implements EntityInterface)
//to implement some common for all subclasses logic
}
}
public class ConcreteBean extends AbstractBean<ConcreteEntity> {
...
//and here we can write only specific for this bean methods
...
}
是第二个例子是不好的做法太的例子吗?