forked from exceptionnotfound/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
46 lines (39 loc) · 1.21 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory
{
class Program
{
/// <summary>
/// The Abstract Factory pattern provides an interface for creating related families of objects
/// without needing to specify the concrete implementations. This pattern is critical for ideas
/// like Dependency Injection.
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
Console.WriteLine("Who are you? (A)dult or (C)hild?");
char input = Console.ReadKey().KeyChar;
RecipeFactory factory;
switch(input)
{
case 'A':
factory = new AdultCuisineFactory();
break;
case 'C':
factory = new KidCuisineFactory();
break;
default:
throw new NotImplementedException();
}
var sandwich = factory.CreateSandwich();
var dessert = factory.CreateDessert();
Console.WriteLine("\nSandwich: " + sandwich.GetType().Name);
Console.WriteLine("Dessert: " + dessert.GetType().Name);
Console.ReadKey();
}
}
}