In my GWT application, I have a class like so:
public class AppActivityMapper implements ActivityMapper {
@Override public Activity getActivity(Place place) {
if(place instanceof ThisPlace) {
return new ThisActivity((ThisPlace)place);
}
if(place instanceof ThatPlace) {
return new ThatActivity((ThatPlace)place);
}
if(place instanceof AnotherPlace) {
return new AnotherActivity((AnotherPlace)place);
}
// you get the idea
}
}
The ActivityMapper, Activity, and Place objects are part of the framework, and the interface implies that this is how it was meant to be used.
However, according to the Liskov Substitution Principle, a method that accepts a type but does a type check for subclasses to infer what action to take is a violation of the principle.
Is GWT's ActivityMapper interface by nature encouraging a violation of the LSP? Or is there another LSP-compliant way to code that method that I haven't thought of?