jeudi 25 janvier 2018

does 10 types of pizza requires 2 power 10 methods If I use decorator pattern?

I started understanding decorator pattern, It flows something like this

Main(){
chikenChillyCheesePizza = new chicken(new chilly(new cheese(new pizza())));
chikenCheesePizza = new chicken(new cheese(new pizza()));
}

The question I would like to ask is when I want a specific flavor of pizza I need to pass those objects in the constructor injection right? Instead I would like to have class that has these methods

static class pizzaMaker{
static chikenChillyCheesePizza() => new chicken(new chilly(new cheese(new pizza())));
static chikenCheesePizza() => new chicken(new cheese(new pizza()));
}

If I have 10 types of pizza then do I need to have 2 power 10 combination of methods in my pizzaMaker class? How would I solve this in a simpler way. Decorator stops creating permutation of objects but does it solve permutation of methods also? How would I achieve this. Any help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire