📄 flyweightfactory.java
字号:
/** * See page 198 of DESIGN PATTERNS [1995]. * Implemented by Blueprint Technologies, Inc. *//** * Package */package test;/** * Imports */import java.util.Hashtable;/** * Creates and manages flyweight objects. Ensures that flyweights * are shared properly. When a client requests a flyweight, the * Flyweight Factory object supplies an existing instance or * creates one, if none exists. */public class FlyweightFactory{ private Hashtable flyweights = new Hashtable(); public Flyweight getFlyweight( Object key ) { Flyweight flyweight = (Flyweight) flyweights.get(key); if( flyweight == null ) { flyweight = new ConcreteFlyweight(); flyweights.put( key, flyweight ); } return flyweight; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -