This is an example of using Design Pattern Factory, i tried to make it simple as possible, you can check it and use it as you want in your future project.