void Test() { // 外部状态 int extrinsicState = 22; FlyweightFactory factory = new FlyweightFactory(); Flyweight fx = factory.GetFlyweight("X"); fx.Operation(--extrinsicState); Flyweight fy = factory.GetFlyweight("Y"); fy.Operation(--extrinsicState); Flyweight fz = factory.GetFlyweight("Z"); fz.Operation(--extrinsicState); Flyweight uf = new UnsharedConcreteFlyweight(); uf.Operation(--extrinsicState); }
static void Main(string[] args) { FlyweightFactory flyweightFactory = new FlyweightFactory(); Flyweight fA = flyweightFactory.GetFlyweight("A"); fA.Operation(10); Flyweight fB = flyweightFactory.GetFlyweight("A"); fB.Operation(9); Flyweight fC = flyweightFactory.GetFlyweight("C"); fC.Operation(8); UnsharedConcreteFlyweight uf = new UnsharedConcreteFlyweight(); uf.Operation(7); Console.WriteLine("fA == fB:" + (fA == fB)); Console.WriteLine("fA == fC:" + (fA == fC)); }
static void Main(string[] args) { int extrinsincstate = 22; FlyweightFactory f = new FlyweightFactory(); Flyweight fx = f.GetFlyweight("X"); fx.Operation(extrinsincstate); Flyweight fy = f.GetFlyweight("Y"); fy.Operation(extrinsincstate); Flyweight fz = f.GetFlyweight("Z"); fz.Operation(extrinsincstate); Flyweight uf = new UnsharedConcreteFlyweight(); uf.Operation(extrinsincstate); Console.ReadKey(); }