-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapeCache.java
More file actions
35 lines (27 loc) · 792 Bytes
/
ShapeCache.java
File metadata and controls
35 lines (27 loc) · 792 Bytes
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
package prototype_pattern;
import java.util.HashMap;
/**
* @ClassName ShapeCache
* @Description TODO
* @Author qulingxiao
* @Date 2020/7/12 8:43
* @Version 1.0
*/
public class ShapeCache {
public static HashMap<String, Shape> shapeCache = new HashMap<String, Shape>();
public static Shape getShape(String id) {
Shape cacheShape = shapeCache.get(id);
return (Shape) cacheShape.clone();
}
public static void loadCache() {
Circle circle = new Circle();
circle.setId("1");
Square square = new Square();
square.setId("2");
Rectangle rectangle = new Rectangle();
rectangle.setId("3");
shapeCache.put("1",circle);
shapeCache.put("2",square);
shapeCache.put("3",rectangle);
}
}