我正在做一些思想实验,研究增强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开发人员团队,那就更好了。你为什么不做这个改变?
最佳答案
仅仅因为它期望在一个给定的地方进行很多活动。
请参见http://blog.ltgt.net/gwt-21-activities/和http://blog.ltgt.net/gwt-21-activities-nesting-yagni/