Learning how to use factoryMethod.

Implemented sample code for factoryMethod.