-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapeFactory.java
44 lines (39 loc) · 1.15 KB
/
ShapeFactory.java
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
// Copyright (C), Razvan Radoi, first of his name
public final class ShapeFactory {
// class ShapeFactory is singleton
public static final ShapeFactory FACTORY_INSTANCE = new ShapeFactory();
private ShapeFactory() {
}
// ShapeFactory returns a shape by a given string
public GeometricShape getShape(final String shapeType) {
if (shapeType.equals("CANVAS")) {
return new Canvas();
}
if (shapeType.equals("LINE")) {
return new Line();
}
if (shapeType.equals("SQUARE")) {
return new Square();
}
if (shapeType.equals("RECTANGLE")) {
return new Rectangle();
}
if (shapeType.equals("CIRCLE")) {
return new Circle();
}
if (shapeType.equals("TRIANGLE")) {
return new Triangle();
}
if (shapeType.equals("DIAMOND")) {
return new Diamond();
}
if (shapeType.equals("POLYGON")) {
return new Polygon();
}
return null;
}
// instance getter
public static ShapeFactory getInstance() {
return FACTORY_INSTANCE;
}
}