jeudi 26 avril 2018

Getting Class Names from User in Decorative Pattern

I am trying to make a pizzashop program. I am using decorative pattern for this purpose. Simply my program is running like this line :

 Pizza basicPizza = new TomatoSauce(new Mozzarella(new PlainPizza()));

For every different topping or different sauce i want to get these information from the user. For instance if user enters "Salami,Cheese" i want these line of code:

Pizza basicPizza = new Salami(new Cheese(new PlainPizza()));

I found some information about reflection also newInstance() method but could not achieve my goal because of the inner classes.

Aucun commentaire:

Enregistrer un commentaire