import java.util.*;
public class FlyweightFactory {
HashMap pool = new HashMap();
public FlyweightFactory() {
pool.put("A" , new ConcreteFlyweight());
pool.put("B" , new ConcreteFlyweight());
pool.put("C" , new ConcreteFlyweight());
}
public Flyweight getFlyweight(String key) {
return (Flyweight)pool.get(key);
}
}
public class Client {
public static void main(String[] args) {
int extrinsicstate = 10;
FlyweightFactory factory = new FlyweightFactory();
Flyweight fa = factory.getFlyweight("A");
fa.operation(--extrinsicstate);
Flyweight fb = factory.getFlyweight("B");
fb.operation(--extrinsicstate);
Flyweight fc = factory.getFlyweight("C");
fc.operation(--extrinsicstate);
UnsharedConcreteFlyweight fu = new
UnsharedConcreteFlyweight();
fu.operation(--extrinsicstate);
}
}