Eliminating GWT ActivityMapper boilerplate

前端 未结 6 1113
盖世英雄少女心
盖世英雄少女心 2021-02-05 16:26

I am using the GWT Activities and Places framework to structure my application and it is turning out nicely. One thing that annoys me though is that the ActivityMapper

6条回答
  •  清酒与你
    2021-02-05 17:23

    One possibility is to have the root of your Place class hierarchy define a createActivity() method, and Place subclasses can return a new instance of the Activity they're associated with.

    @Override
    public Activity getActivity(Place place) {
        return ((BaseAppPlace)place).createActivity();
    }
    

    This has the advantage of having eliminated that if/else block, and having one less place to modify when you add a new Place/Activity. The downside of this is that it kindof pollutes your Place class with Activity creation behavior, even if you're just delegating to a Ginjector.

提交回复
热议问题