GWT Place Class增强可行性

时间:2011-08-26 18:53:14

标签: java gwt gwt-mvp

我正在考虑实验调查增强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开发团队。你为什么不做这个改变?

1 个答案:

答案 0 :(得分:2)

仅仅因为预计单个地方有很多活动。

请参阅http://blog.ltgt.net/gwt-21-activities/http://blog.ltgt.net/gwt-21-activities-nesting-yagni/