design - Designing pizza shop : Change Ingredients or base after pizza is fully constructed? -
I'm trying to solve the problem of pizza shop. They will sell some pizza varieties in the pizza shop and they will also provide toppings in the menu. Now imagine a situation in which the pizza shop will have to get prices for each combination of pizza and toppings.
This is an example of a decorator pattern and it can be prepared as a compliance:
Public Abstract class BasePizza {protected double myprice; Public Virtual Double GetPrice () {this return.myPrice; }} Public Abstract Class ToppingsDecorator: BasePizza {Secure BasePizza Pizza; Public ToppingDecorator (Baspaeja Pizza Todcorate) {this.pizza = pizzaToDecorate; } Double Override GetPrice () {Return (this.pizza.GetPrice () + this.myPrice); }} Class program {[STAThread] static zero main () {// client-code Margarita pizza = new margarita (); Console.lightline ("plain path:" + pizza. Gatepress (). Toasting ()); Extra Chase is doing more Cheyes = New Extra Chase Tapping (Pizza); Extra Chasing Some More Academic = New Extra Chasing (more Chase); Console.reiteline ("plain extravagance with double extra cheese": + some more chase .Getpris (). Toasting ()); Mushroom more mushrooms + Close new mushrooms (more chisy); Console.lightline ("plain merriment with double extra cheese with mushrooms:" + more mushroom .Getpris (). Toasting ()); Burning is more falling; Burning = new burn-painting (more mushrooms); Console White line ("Simple merges with double extra paneer with mushroom with Jalipeno": + more Zlpano GatePrice (). Toasting ()); Console.ReadLine (); }} Public Sector Margherita: BasePage {Public Margarita () {this.myPrice = 6.99; }} Public Square Gourmet: Basepage {Public Massage () {this.myPrice = 7.49; }} Public Class Xtra Chasing: Topping Decokerator {Public Extra Chasing (Basepayja Pizza Todacourt): Base (Pizzaotocortret) {this.myPrice = 0.99; }} Public Class MushroomToping: Topping Detector {Public MushroomToTouching (BasePage Pizza Todcorate): Base (Pizzatodocorrect) {this.myPrice = 1.49; }} Public Square Jalpaño Topping: Topping Decritor {Public Supplements Topping (Basepaya Pizza Todacourt): Base (Pizzatodicorate) {this.myPrice = 1.49; }}
However the problem arises when I want to change the component or pizza base for a pizza already built. For example, if the customer has ordered a pizza with a certain type of base (called a thin layer) and some topping (mushroom-topping, cheese) and after a short time the customer calls again and the pizza base is on another basis Asks for change (Italian pizza base). How can I handle it in design?
Edit
It seems that this problem can not be resolved by the decorator pattern. I wonder whether there is any other pattern Will solve the problem in a beautiful way?
Pizza and a customized pizza made for your design, you can make a pre-made pizza, where You have a thin layer object, cheese etc. And for the customized pizza you just need to ask the user what ingredients he wants, then collect all the objects then if he wants to make corning instead of mushroom, / P>
for example If I have a pizza with a certain type of base (called a thin layer) and some are called topping (mushroom-topping, paneer)
and the situation is
Customers want to change the pizza base on some other basis (called Italian pizza bass) or tap cornering to convert mushrooms to toppings.
This is a custom Pizza is just like you are saying "I leave mushrooms A. I want the component "
Comments
Post a Comment