-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapeFactory.java
32 lines (30 loc) · 1.06 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
// clasa de tip Factory pentru implementarea factory pattern
// si totodata si sigleton pattern
public final class ShapeFactory implements Factory {
public static final ShapeFactory FACTORY = new ShapeFactory();
private ShapeFactory() {
}
@Override
public Shape createShape(final String type, final String[] shapeParameters) {
switch (type) {
case "CANVAS":
return new Canvas(shapeParameters);
case "LINE":
return new Line(shapeParameters);
case "SQUARE":
return new Square(shapeParameters);
case "RECTANGLE":
return new Rectangle(shapeParameters);
case "TRIANGLE":
return new Triangle(shapeParameters);
case "DIAMOND":
return new Diamond(shapeParameters);
case "CIRCLE":
return new Circle(shapeParameters);
case "POLYGON":
return new Polygon(shapeParameters);
default:
return null;
}
}
}