using virtual method dispatch instead of a switch