public class
ShapeCache
{
private static
Hashtable
<
String
,
Shape
>
shapeMap
=
new
Hashtable
<
String
,
Shape
>
();
public static
Shape getShape
(
String
shapeId
) {
Shape cachedShape
=
shapeMap
.
get
(
shapeId
);
return
(
Shape
)
cachedShape
.
clone
();
}
//
对每种形状都运行操作创建该形状
shapeMap.put(shapeKey, shape);
public static
void
loadCache
() {
Circle circle
=
new
Circle
();
circle
.
setId
(
"1"
);
shapeMap
.
put
(
circle
.
getId
(),
circle
);
}
}