Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SimpleFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- PizzaStore pizzaStore = new PizzaStore(new SimplePizzaFactory());
- pizzaStore.OrderPizza("cheese");
- Console.ReadKey();
- }
- }
- class PizzaStore
- {
- private SimplePizzaFactory _factory;
- public PizzaStore(SimplePizzaFactory factory)
- {
- _factory = factory;
- }
- public Pizza OrderPizza(string type)
- {
- Pizza pizza;
- pizza = _factory.CreatePizza(type);
- pizza.Prepare();
- pizza.Bake();
- pizza.Cut();
- pizza.Box();
- return pizza;
- }
- }
- class SimplePizzaFactory
- {
- private Pizza _pizza = null;
- public Pizza CreatePizza(string type)
- {
- switch (type)
- {
- case "cheese":
- _pizza = new CheesePizza();
- break;
- case "greek":
- _pizza = new GreekPizza();
- break;
- case "pepperomi":
- _pizza = new Pepperoni();
- break;
- }
- return _pizza;
- }
- }
- class CheesePizza : Pizza
- {
- public CheesePizza()
- {
- _type = "Сырная";
- }
- }
- class GreekPizza : Pizza
- {
- public GreekPizza()
- {
- _type = "Греческая";
- }
- }
- class Pepperoni : Pizza
- {
- public Pepperoni()
- {
- _type = "Пепперони";
- }
- }
- class Pizza
- {
- protected string _type;
- public void Prepare()
- {
- Console.WriteLine("Готовим " + _type + "...");
- }
- public void Bake()
- {
- Console.WriteLine("Запекаем...");
- }
- public void Cut()
- {
- Console.WriteLine("Режем на аккуратные кусочки...");
- }
- public void Box()
- {
- Console.WriteLine("Упаковываем...");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement