PizzaShopDesignPattern

Idea: To work with following Design Patterns: Decorator, Factory, Observer and Adapter.
Background: C#Note OOP3 + https://www.dofactory.com/net/design-patterns


Decorator

In this task, a PizzaShop must be implemented using the Decorator design pattern.
A simple Console project must be created, where the following classes are implemented:




 

Test the classes in Main or a worker.



Factory


Expand the Pizza Shop to implement a Factory Design Pattern to create Pizza objects. MakePizza () can take an array of string as argument (a list of ingredients to add to the pizza (if you do not want a Margarita J e.g. Bacon, Ham, Pepperoni ...). In a foreach loop, MakePizza () can call a private help method AddIngredients(), which can include a switch statement to determine what "decorations" the Margarita should have.




 

Test the classes in Main or a worker.

 

Observer


Expand the Pizza Shop with the Observer Design Pattern, for example by adding a PizzaMan and a PizzaOven ala the following:

 

 

TakeOrder should call MakePizza () on PizzaFactory and PreparePizza () on PizzaOven.
PreparePizza may have the following appearance:

public void preparePizza(AbstractPizza p)
{

Task.Factory.StartNew(() =>
{
int preparetime = random.Next(5, 15);
System.Threading.Thread.Sleep(preparetime*1000);
NotifyObservers(p);
});
}

and NotifyObservers the following appearance:

private void NotifyObservers(AbstractPizza pizza)
{
foreach (var observer in _observers)
{
observer.Notify(pizza);
}
}


Test the classes in Main or a worker.


Adapter


Expand the Pizza Shop with Adapter Design Pattern to introduce a Pizza Menu with beverages (e.g. beer or water) as follows:

 

 

Strategy


Expand the Pizza Shop with Strategy Design Pattern, for example. be with different prices for Lunch (-20%) and Night (+ 10%), but there could be many rules, all implemented in different implementations of IPriceStrategy.

 

 

Initially, Client is our PizzaMan who uses Strategy pattern to find the price possible with some logic ala:

public enum TimeOfDay { Lunch, Evening, Night };

....

switch (DayTime)
{
case TimeOfDay.Evening: price = EveningPriceStrategy.CalculatePrice(pizza); break;
case TimeOfDay.Lunch: price = LunchPriceStrategy.CalculatePrice(pizza); break;
case TimeOfDay.Night: price = NightPriceStrategy.CalculatePrice(pizza); break;
}

 

You can always make testing i.e. unittesting or build an GUI upon the classes.

Nice pleasures
Henrik