public void Operation(String key, boolean shared) { Flyweight flyweight; if (shared) { flyweight = FlyweightFactory.getFlyweight(key); } else { flyweight = new UnsharedConcreteFlyweight(key); } flyweight.Operation("changed extrinsicly"); }
public void showFlyweight() { fly1.operation(); fly2.operation(); fly3.operation(); fly4.operation(); fly5.operation(); fly6.operation(); int objSize = factory.getFlyweightSize(); System.out.println("objSize = " + objSize); }
/** @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); }