SimplePizzaFactory.CreatePizzaaccepts the typestringand returns the correspondingPizza.PizzaStorereceives the factory through its constructor and delegates creation to it.- The client’s first run orders a
CheesePizza.
7.3 Factory Pattern Lab
This assignment is based on the Pizza Store in Head First Design Patterns (p. 112-157)
Work through the stories in order. Use the acceptance criteria to check each feature, and complete the nested tasks using the specified names, values, and scenarios.
| Store | Ingredient factory | Expected dough |
|---|---|---|
| NYPizzaStore | NYIngredientFactory |
ThinCrustDough |
ChicagoPizzaStore |
ChicagoIngredientFactory |
ThickCrustDough |
SimplePizzaFactory.CreatePizza accepts the type string and returns the corresponding Pizza.PizzaStore receives the factory through its constructor and delegates creation to it.Cheese Pizza.SimplePizzaFactory with a method called CreatePizza that takes a string…In the Factories folder, define a new class named SimplePizzaFactory with a method called CreatePizza that takes a string parameter named type and returns a Pizza object.
OrderPizza method in the PizzaStore class and paste it in the SimplePizzaFactory class's…Cut the if/else block from the OrderPizza method in the PizzaStore class and paste it in the SimplePizzaFactory class's CreatePizza method.
PizzaStore class a constructor with a SimplePizzaFactory type argument named factory and a field of type…Give the PizzaStore class a constructor with a SimplePizzaFactory type argument named factory and a field of type SimplePizzaFactory named factory.
PizzaStore constructor, assign the factory field to the factory parameter.SimplePizzaFactory and pass it in to the PizzaStore constructor.OrderPizza method, call the factory object's CreatePizza method and pass in the type parameter as an argument.Cheese Pizza.Chicago Style Cheese Pizza was ordered.Cheese Pizza was ordered.ChicagoPizzaStore and NYPizzaStore inherit from PizzaStore.ChicagoPizzaStore and NYPizzaStore inherit from PizzaStore.PizzaStore constructor, factory field and instantiation of the PizzaStore from the Main method.PizzaStore class named CreatePizza that takes a string type named type.PizzaStore class abstract.CreatePizza method, call the CreatePizza method from the class.CreatePizza method in the SimplePizzaFactory class and paste it into both the ChicagoPizzaStore and NYPizzaStore…Copy the CreatePizza method in the SimplePizzaFactory class and paste it into both the ChicagoPizzaStore and NYPizzaStore classes. Make the methods overrides.
"Style" pizzas inherit from their base style pizzas. (Example: ChicagoStyleCheesePizza inherits CheesePizza)ChicagoPizzaStore class's CreatePizza method, instantiate the Chicago versions of the objects and change the Name…In the ChicagoPizzaStore class's CreatePizza method, instantiate the Chicago versions of the objects and change the Name properties to read "Chicago Cheese Pizza".
SimplePizzaFactory class.ChicagoPizzaStore.PizzaStore pizzaStore = new ChicagoPizzaStore();Chicago Style Cheese Pizza was ordered.ChicagoPizzaStore to a NYPizzaStore.Cheese Pizza was ordered.Pizza class properties for Dough and Sauce.Pizza class a protected field of type ArrayList named toppings and instantiate it at the field level.Prepare method.Pizza class properties for Dough and Sauce.Pizza class a protected field of type ArrayList named toppings and instantiate it at the field level.Prepare method.Console.WriteLine("Preparing " + this.Name);
Console.WriteLine("Tossing " + this.Dough);
Console.WriteLine("Adding " + this.Sauce);
Console.WriteLine("Adding toppings: ");
for (int i = 0; i < toppings.Count; i++)
{
Console.WriteLine(" " + toppings[i]);
}Bake method:Console.WriteLine("Bake for 25 minutes at 350.");Box method:Console.WriteLine("Place pizza in official PizzaStore box.");Cut method:Console.WriteLine("Cutting the pizza into diagonal slices.");NYStyleCheesePizza class and paste the code below inside of it.this.Name = "New York Style Cheese Pizza";
this.Dough = "Thin Crust Dough";
this.Sauce = "Marinara Sauce";
this.toppings.Add("Grated Reggiano Cheese");ChicagoStyleCheesePizza class and paste the code below inside of it.this.Name = "Chicago Style Deep Dish Cheese Pizza";
this.Dough = "Extra Thick Crust Dough";
this.Sauce = "Plum Tomato Sauce";
this.toppings.Add("Shredded Mozzarella Cheese");ChicagoStyleCheesePizza class, override the Cut method and paste the code below inside of it.Console.WriteLine("Cutting the pizza into square slices.");Console:Console.WriteLine($"Ethan ordered a {pizza.Name}. \n");ChicagoPizzaStore and order an additional cheese pizza.Console out what kind of pizza Joel ordered.
Line 1: Preparing New York Style Cheese Pizza
Line 2: Tossing Thin Crust Dough
Line 3: Adding Marinara Sauce
Line 4: Adding toppings:
Line 5: Grated Reggiano Cheese
Line 6: Bake for 25 minutes at 350.
Line 7: Cutting the pizza into diagonal slices.
Line 8: Place pizza in official PizzaStore box.
Line 9: Ethan ordered a New York Style Cheese Pizza.
Line 10:
Line 11: Preparing Chicago Style Cheese Pizza
Line 12: Tossing Extra Thick Crust Dough
Line 13: Adding Plum Tomato Sauce
Line 14: Adding toppings:
Line 15: Shredded Mozzarella Cheese
Line 16: Bake for 25 minutes at 350.
Line 17: Cutting the pizza into square slices.
Line 18: Place pizza in official PizzaStore box.
Line 19: Joel ordered a Chicago Style Cheese Pizza.CreatePizza method that should be in the NYPizzaStore.PizzaStore, the pizza object should have the following Values/Types.OrderPizza in Main. The pizza object should have the following Values/Types.Dough CreateDough();
Sauce CreateSauce();
Cheese CreateCheese();
Veggie[] CreateVeggies();
Pepperoni CreatePepperoni();
Clam CreateClams();ChicagoIngredientFactory class and a new NYIngredientFactory class. Have them both…In the Factories folder, define a new ChicagoIngredientFactory class and a new NYIngredientFactory class. Have them both implement the IPizzaIngredientFactory interface.
Chicago and New York Ingedients folders, have all classes inherit from their proper parent class.NYIngredientFactory, return the proper ingredient object in each method and return a list of Garlic, Onion, Mushroom…In the NYIngredientFactory, return the proper ingredient object in each method and return a list of Garlic, Onion, Mushroom and RedPepper for the Veggies.
ChicagoIngredientFactory, return the proper ingredient object in each method and return a list of Garlic and…In the ChicagoIngredientFactory, return the proper ingredient object in each method and return a list of Garlic and RedPepper for the Veggies.
Pizza class...Dough, Sauce, Veggies, Cheese, Pepperoni and Clams and remove the string properties for Dough, Sauce…Define properties for Dough, Sauce, Veggies, Cheese, Pepperoni and Clams and remove the string properties for Dough, Sauce and toppings.
Prepare method abstract and the Pizza class abstract.CheesePizza class...ingredientFactory.ingredientFactory and inside the constructor…Define a constructor with a parameter of type IPizzaIngredientFactory named ingredientFactory and inside the constructor assign the field.
Prepare method.Prepare method, paste the code below:Console.WriteLine("Preparing: " + this.Name);
this.Dough = this.ingredientFactory.CreateDough();
this.Sauce = this.ingredientFactory.CreateSauce();
this.Cheese = this.ingredientFactory.CreateCheese();ClamPizza, PepperoniPizza and VeggiePizza classes and call the proper methods. (i.e. the…Repeat the previous step for the ClamPizza, PepperoniPizza and VeggiePizza classes and call the proper methods. (i.e. the clam pizza should be creating clams for the pizza).
Chicago Pizzas and NY Pizzas and all classes inside them.This is where the beauty of the Factory Pattern comes in. We do not need more "concrete" classes to make the object we want.
ChicagoPizzaStore and NYPizzaStore classes...CreatePizza, instantiate ChicagoIngredientFactory in ChicagoPizzaStore and NYIngredientFactory in…At the beginning of CreatePizza, instantiate ChicagoIngredientFactory in ChicagoPizzaStore and NYIngredientFactory in NYPizzaStore. Name the local variable ingredientFactory.
ingredientFactory into each Pizza constructor.Joel orders from cheese to clam.OrderPizza.CreatePizza method that should be in the NYPizzaStore.Prepare method.Prepare method.PizzaStore, the pizza object should have the following Values/Types.
Type Value
pizza {FactoryPattern.CheesePizza}
Cheese {FactoryPattern. ReggianoCheese}
Clams null
Dough {FactoryPattern.ThinCrustDough}
Name "New York Style Cheese Pizza"
Pepperoni null
Sauce {FactoryPattern.MarinaraSauce}
Veggies null
ingredientFactory {FactoryPattern.NYIngredientFactory}OrderPizza in Main. The pizza object should have the following Values/Types.
Type Value
pizza {FactoryPattern.ClamPizza}
Cheese {FactoryPattern.MozzarellaCheese}
Clams {FactoryPattern.FrozenClams}
Dough {FactoryPattern.ThickCrustDough}
Name "Chicago Style Clam Pizza"
Pepperoni null
Sauce {FactoryPattern.PlumTomatoSauce}
Veggies null
ingredientFactory {FactoryPattern.ChicagoIngredientFactory}Return to each story and verify its acceptance criteria. Preserve the submission format and destination stated in the activity; a reading, setup guide, lab, video demonstration, and oral final may require different evidence.
Build a simple factory. Add franchises Make some pizzas Implement an ingredient factory.