Accessing Superclasses' fields
What is the best practice for accessing my superclass' fields? I understand the best approach for accessing other class' fields is to access them through get and sets. However, there is a special relationship you are making with inheritance. The fact that you are specializing an implementation means that you require/know about the entire generalization (i.e. superclass). So does it really make sense to have gets and sets for the fields in your superclass so the subclass can get to them? or is it acceptable to access the fields directly?
Ideally I would want to use the 'ever so talked about' old school "private protected" to encapsulate my code. IMHO, this was something that should not have been removed because other developers that are working in my package might not fully grasp my design and start using data items that they shouldn't.
here is little code snippets to help clarify what I am talking about.
Scenario 1:
publicabstractclass SuperClass{
private Value val;
protected Value getValue(){return val;}
protectedvoid setValue(Value val){ this.val = val;}
publicabstract doWork();
}
publicclass SubClassextends SuperClass{
publicvoid doWork(){
Value val = super.getValue();
val.doWork();
}
}
Scenario 2:
publicabstractclass SuperClass{
protected Value val;
publicabstract doWork();
}
publicclass SubClassextends SuperClass{
publicvoid doWork(){
val.doWork();
}
}
Direct access is easier to write and at this level seems appropiate
Thanks for your comments
Lance

