我有 A 类,它配置自己解析 xml 文件。B 类扩展 A 并配置自己解析一个 xml 文件,该文件具有比前一个更多的标签。
class A {
protected String mFoo;
protected loadFromXml (...){
...
mFoo = ...
...
}
}
class B extends A {
protected String mBar;
protected loadFromXml (...){
super.loadFromXml(...);
...
mBar = ...
...
}
}
现在,我有 ActivityA,它通过 A 类进行自我配置:
class ActivityA extends Activity {
protected A mAInstance;
public void onCreate(Bundle savedInstanceState) {
...
mAInstance.loadFromXml(...);
...
other code...
...
}
}
和活动B:
class ActivityB extends ActivityA{
protected B mBInstance;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mBInstance.loadFromXml(...);
...
}
}
现在,问题是:ActivityB 拥有 mAInstance 和 mBInstance,它们共享相同数据 (mFoo) 的子集。如何仅加载 mBInstance?我当然需要在ActivityB的onCreate中调用super ...