/** * 字母 * @author stone * */ public class Letter { private String name; public Letter(String name) { this.name = name; } public String getName() { return name; } } /** * 一个产生字母对象的 享元工厂(单例工厂) * @author stone * */ public class LetterFactory { private…
参考资料 • 维基百科:https://en.wikipedia.org/wiki/Flyweight_pattern • 百度百科:http://baike.baidu.com/link?url=RIhzC8-C6HUnAX6DqI5IfjawN3yhOckKvj8wWLL9zL4OAqK_I4xpi55aAjTpQdm7mKYZj7fKGW-I4-qXcNsj-q Flyweight模式简介 GoF:Use sharing to support large numbers of fine-g…
享元模式的主要目的.意图是为对象的大量使用提供一种共享机制.该模式的思想重在复用.共享复用.像文字.列表中的格子等这类多数都是需要考虑复用技术,否则必将大量耗费内存空间而使资源以及性能等大量耗费.该模式的类关系图参考如下: 模式的编码结构参考如下: namespace flyweight { class Flyweight {}; class ConcreteFlyweight : public Flyweight {}; class UnsharedFlyweight : public Fly…
享元模式:运用共享技术有效地支持大量细粒度的对象. 适用场合:假设一个应用程序适用了大量的对象.而大量的这些对象造成了非常大的存储开销时就应该考虑使用. 首先定义一个IFlyweight接口 public interface IFlyweight { public void operation(int extrinsicstate); } 接着定义一个ConcreteFlyweight继承IFlyweight public class ConcreteFlyweight implements I…