Skip to content

Commit

Permalink
Create ShapeFactory.java
Browse files Browse the repository at this point in the history
  • Loading branch information
SHASHANK0712 authored Oct 17, 2022
1 parent 90c3100 commit 10080c3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Structural/Flyweight/java/shape-circle-demo/ShapeFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.HashMap;

public class ShapeFactory {

// Uncomment the compiler directive line and
// javac *.java will compile properly.
// @SuppressWarnings("unchecked")
private static final HashMap circleMap = new HashMap();

public static Shape getCircle(String color) {
Circle circle = (Circle)circleMap.get(color);

if(circle == null) {
circle = new Circle(color);
circleMap.put(color, circle);
System.out.println("Creating circle of color : " + color);
}
return circle;
}
}

0 comments on commit 10080c3

Please sign in to comment.