任何人都可以解釋如何做享元模式工作的下面的代碼:享元模式
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;
}
}
}
感謝。
請採取正確格式化你的問題的時間。 – dcastro 2014-12-09 12:43:44