使用以下样式之一从抽象父类声明方法的优点/缺点是什么:
选项1:
家长班:
protected Object retrieve(String id, Object model){
return null;
}
儿童班:
@Override
public String retrieve(Object model) {
if (model instanceof Car)
// ... somehow get id ...
return getInfo(id, (Car)model);
return null;
}
或者...
选项 2:
家长班:
protected abstract Object retrieve(String id, Object model);
儿童班:
public String retrieve(String id, Object model) {
if (model instanceof Car)
return getInfo(id, (Car)model);
return null;
}