using polymorphism to replace the swith statements