samedi 21 avril 2018

Nested call in Java (Decorator Pattern)

I'm working on a basic Pizza program.The program add toppings into pizza by using Decorator Pattern Design.

public static void main(String[] args) {
    Pizza pizza = new PizzaBakery();
    //lets put Onion,Pepper and Salami into pizza:
    pizza = new Salami(new Pepper(new Onion(pizza)));}

My code works well and manage to create pizza&put its toppings. The problem is that, I'll take pizza&Toppings orders from an input file.

Input file example:

AddTopping 7 HotPepper Soudjouk Salami (7 is the ID of the pizza)

AddTopping 1 HotPepper Onion

.....

and adding toppings into pizza must be nested(like new Salami(new Pepper(new Onion(pizza))) ) .Is there any different way/method to use instead of writing many if-else statements ?

Aucun commentaire:

Enregistrer un commentaire