MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / ShapeFactory1

Class ShapeFactory1

patterns/ShapeFactory1.java:10–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import patterns.shapes.*;
9
10public class ShapeFactory1 implements FactoryMethod {
11 @Override public Shape create(String type) {
12 switch(type) {
13 case "Circle": return new Circle();
14 case "Square": return new Square();
15 case "Triangle": return new Triangle();
16 default:
17 throw new BadShapeCreation(type);
18 }
19 }
20 public static void main(String[] args) {
21 FactoryTest.test(new ShapeFactory1());
22 }
23}
24/* Output:
25Circle[0] draw
26Circle[0] erase

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected