每天一个设计模式之Flyweight

http://www.oodesign.com/flyweight-pattern.html

 

Some programs require a large number of objects that have some shared state among them.例如一个游戏中的士兵,创建大量士兵对象将消耗大量内存。但是我们可以发现:每个士兵的位置和health各有不同,但是持有的武器,行进速度等很多特性都是相同的。

 

Flyweight模式处理的问题就是:

The intent of this pattern is to use sharing to support a large number of objects that have part of their internal state in common where the other part of state can vary.

你可能感兴趣的:(设计模式,游戏)