Use a virtual method rather than a set of nasty dynamic casts.