flyweightfactory.java~1~

来自「《深入浅出设计模式》的完整源代码」· JAVA~1~ 代码 · 共 40 行

JAVA~1~
40
字号
/** * See page 198 of DESIGN PATTERNS [1995]. * Implemented by Blueprint Technologies, Inc. *//** * Package */package com.blueprint.patterns.gamma.structural.flyweight;/** * 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 + =
减小字号Ctrl + -
显示快捷键?