-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapeFactory.cs
More file actions
48 lines (41 loc) · 1.34 KB
/
Copy pathShapeFactory.cs
File metadata and controls
48 lines (41 loc) · 1.34 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProgrammingLanguageIDE
{
public class ShapeFactory
{
public Shape getShape(String shapeType)
{
shapeType = shapeType.ToUpper().Trim(); //you could argue that you want a specific word string to create an object but I'm allowing any case combination
if (shapeType.Equals("CIRCLE"))
{
return new Circle();
}
else if (shapeType.Equals("RECTANGLE"))
{
return new Rectangle();
}
else if (shapeType.Equals("SQUARE"))
{
return new Square();
}
else if (shapeType.Equals("TRIANGLE"))
{
return new Triangle();
}
else if (shapeType.Equals("DRAWTO"))
{
return new DrawLine();
}
else
{
//if we get here then what has been passed in is inkown so throw an appropriate exception
System.ArgumentException argEx = new System.ArgumentException("Factory error: " + shapeType + " does not exist");
throw argEx;
}
}
}
}