13
...
14
15
{
16
17
string = str;
18
19
}
//end ConcreteFlyweight(...)
20
21
public
void
operation()
22
23
...
24
25
{
26
27
System.out.println("Concrete---Flyweight : " + string);
28
29
}
//end operation()
30
31
}
//end class ConcreteFlyweight
32
33
实现一个工厂方法类:
1
package
Flyweight;
2
3
import
java.util.Hashtable;
4
5
public
class
FlyweightFactory
6
7
...
8
9
{
10
11
private
Hashtable flyweights =
new
Hashtable();
//----------------------------1
12
13
public
FlyweightFactory() ...{}
14
15
public
Flyweight getFlyWeight(Object obj)
16
17
...
18
19
{
20