我的意思是:爲什麼在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
...
}
是第二個例子是不好的做法太的例子嗎?