-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPizzaStore.cs
More file actions
64 lines (57 loc) · 1.81 KB
/
PizzaStore.cs
File metadata and controls
64 lines (57 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CreationalPatterns.FactoryMethod
{
public abstract class PizzaStore
{
public Pizza OrderPizza(PizzaType type)
{
// calls the factory method to create pizza
Pizza pizza = CreatePizza(type);
pizza.Prepare();
pizza.Bake();
pizza.cut();
pizza.box();
return pizza;
}
// A facotry method
// 1. is abstract so the subclass are counted on to handle object creation.
// 2. returns a Product.
// 3. isolates the client from knowing what of concrete Product is actually created.
// 4. may be parameterized (or not) to select among several variations of a product.
protected abstract Pizza CreatePizza(PizzaType type);
}
public class AmericanPizzaStore : PizzaStore
{
protected override Pizza CreatePizza(PizzaType type)
{
switch (type)
{
case PizzaType.Cheese:
return new AmericanCheesePizza();
case PizzaType.Veggie:
return new AmericanVeggiePizza();
default:
throw new NotImplementedException();
}
}
}
public class ItalianPizzaStore : PizzaStore
{
protected override Pizza CreatePizza(PizzaType type)
{
switch (type)
{
case PizzaType.Cheese:
return new ItalianCheesePizza();
case PizzaType.Veggie:
return new ItalianVeggiePizza();
default:
throw new NotImplementedException();
}
}
}
}