我正在进行思想实验来调查增强 Place 类的可行性。假设 Google 会为我们提供这样的增强功能,那么 Place 类的以下增强功能会有所帮助吗?
让我们说 Place 类被增强为具有方法
setActivity(Activity act)
然后,我们将能够做到这一点:
public class StartActivity extends AbstractActivity implements Presenter {
private ClientFactory clientFactory;
private String name;
public StartActivity(StartPlace place, ClientFactory clientFactory) {
this.clientFactory = clientFactory;
this.name = place.getName();
place.setActivity(this);
}
}
这样 ActivityMapper 就会如此简单......
public class DenLapehActivityMapper
implements ActivityMapper{
@Override
public Activity getActivity(Place place){
return place.getActivity();
}
}
然而,我的思想实验,权衡当前的情况,导致我不得不做这些
abstract public class DenLapehPlace
extends Place{
private Activity activity;
public Activity getActivity(){
return activity;
}
public void setActivity(Activity activity){
this.activity = activity;
}
}
public class DenLapehActivityMapper
implements ActivityMapper{
@Override
public Activity getActivity(Place place){
if (place instanceof DenLapehPlace)
return ((DenLapehPlace)place).getActivity();
return null;
}
}
或者更糟糕的是,遵循示例/教程......
public class DenLapehActivityMapper
implements ActivityMapper{
@Override
public Activity getActivity(Place place){
if (place instanceof AyamDenLapehPlace)
return KurungAyamActivity;
if (place instanceof ItekDenLapehPlace)
return KurungItekActivity;
if (place instanceof KabauDenLapehPlace)
return KurungKabauActivity;
if (place instanceof KancilDenLapehPlace)
return KurungKancilActivity;
etc, etc, etc ...
return null;
}
}
如果你是 GWT 开发团队,是否有任何技术动机(或消极动机)来做出这种改变?更好的是,如果您是 GWT 开发团队。你为什么不做这个改变?