谁能解释 Flyweight 模式的以下代码如何工作:
public class FlyweightFactory {
Hashtable hash = new Hashtable();
public BallFlyweight getFlyweight(int r, Color col, Container c, AStrategy a) {
BallFlyweight tempFlyweight = new BallFlyweight(r,col,c,a),
hashFlyweight = ((BallFlyweight)hash.get(tempFlyweight));
if(hashFlyweight != null)
return hashFlyweight;
else {
hash.put(tempFlyweight,tempFlyweight);
return tempFlyweight;
}
}
}
谢谢。