If you’re writing a GWT application you are most likely following the MVP pattern. With GWT 2.1 the Activities and Places API was introduced and while it’s not strictly an MVP framework, it’s a good base for the architecture of your application.
A core component of Activities and Places is the ActivityMapper
interface. Its role is simple - you get a Place
and based on it an appropriate Activity
should be returned. There’s one problem - you most likely will want to choose the Activity
based on the type of the provided Place
. The usual approach (mentioned even in the official documentation) is a long chain of if (place instanceof CustomPlace) else if (place instanceof CustomPlace2)
… etc. You might have a similar if/else
chain somewhere else in your application where you want to react to a PlaceChangedEvent
. If you add a new Place
, you have to remember to add (another…) if else
in all those places.