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
There isn't a great answer yet. I have code generation schemes in mind, but it's all scribbles on white boards at the moment. For Gin users it seems like a Place Scope might be handy.
Re: the if / else cascade, one common approach is to make your Place objects implement the visitor pattern. E.g. let's assume you have AssistedInject set up for your activities (and forgive the sloppy field injection, it's just a sketch).
class BasePlace extends Place {
T acceptFilter(PlaceFilter filter);
}
interface PlaceFilter {
T filter(FooPlace place);
T filter(BarPlace place);
T filter(BazPlace place);
}
public class MainActivities implements ActivityMapper {
@Inject FooFactory fooMaker;
@Inject BarFactory barMaker;
@Inject BazFactory bazMaker;
public Activity getActivity(PlaceChangeEvent e) {
return ((BasePlace)e.getPlace()).acceptFilter(
new PlaceFilter() {
Activity filter(FooPlace place) {
return fooMaker.create(place);
}
Activity filter(BarPlace place) {
return barMaker.create(place);
}
Activity filter(BazPlace place) {
return bazMaker.create(place);
}
})
}
}