/** @param args */ public static void main(String[] args) { int i = 20; FlyweightFactory factory = new FlyweightFactory(); Flyweight flyweight1 = factory.getFlyweight("X"); flyweight1.operate(--i); Flyweight flyweight2 = factory.getFlyweight("Y"); flyweight2.operate(--i); Flyweight flyweight3 = factory.getFlyweight("Z"); flyweight3.operate(--i); }
public void Operation(String key, boolean shared) { Flyweight flyweight; if (shared) { flyweight = FlyweightFactory.getFlyweight(key); } else { flyweight = new UnsharedConcreteFlyweight(key); } flyweight.Operation("changed extrinsicly"); }