static void Main(string[] args) { // Arbitrary extrinsic state int extrinsicstate = 22; FlyweightFactory factory = new FlyweightFactory(); // Work with different flyweight instances IFlyweight fx = factory.GetFlyweight("X"); fx.Operation(--extrinsicstate); IFlyweight fy = factory.GetFlyweight("Y"); fy.Operation(--extrinsicstate); IFlyweight fz = factory.GetFlyweight("Z"); fz.Operation(--extrinsicstate); UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight(); fu.Operation(--extrinsicstate); // Wait for user Console.ReadKey(); }
public void Test() { Console.WriteLine("单纯享元模式"); // 初始化 享元工厂 FlyweightFactory factory = new FlyweightFactory(); // 通过享元工厂类来创建享元类 IFlyweight fly = factory.Factory('a'); fly.Operation("罗马字符"); fly = factory.Factory('b'); fly.Operation("阿拉伯字符"); fly = factory.Factory('a'); fly.Operation("阿拉伯字符"); fly = factory.Factory('b'); fly.Operation("罗马字符"); }
public void Test() { Console.WriteLine("复合享元模式"); // 初始化 享元工厂 FlyweightFactory factory = new FlyweightFactory(); // 通过享元工厂类来创建享元类 IFlyweight fly = factory.Factory("abc"); fly.Operation("罗马字符"); fly = factory.Factory("bca"); fly.Operation("阿拉伯字符"); fly = factory.Factory("cba"); fly.Operation("阿拉伯字符"); fly = factory.Factory("abcba"); fly.Operation("罗马字符ZZZ"); }
public void Launch() { int extrinsicState = 22; FlyweightFactory factory = new FlyweightFactory(); IFlyweight flyweightA = factory.GetFlyweight("Flyweight A"); IFlyweight flyweightB = factory.GetFlyweight("Flyweight B"); IFlyweight flyweightC = factory.GetFlyweight("Flyweight C"); flyweightA.Operation(--extrinsicState); flyweightB.Operation(--extrinsicState); flyweightC.Operation(--extrinsicState); }
public void UsageMethod() { int extrinsicstate = 22; FlyweightFactory factory = new FlyweightFactory(); IFlyweight fx = factory.GetFlyweight("X"); fx.Operation(--extrinsicstate); IFlyweight fy = factory.GetFlyweight("Y"); fy.Operation(--extrinsicstate); IFlyweight fz = factory.GetFlyweight("Z"); fz.Operation(--extrinsicstate); UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight(); fu.Operation(--extrinsicstate); }
void Main() { int size = 22; FlyweightFactory factory = new FlyweightFactory(); IFlyweight fx = factory.GetFlyweight("X"); fx.Operation(--size); IFlyweight fy = factory.GetFlyweight("Y"); fy.Operation(--size); IFlyweight fz = factory.GetFlyweight("Z"); fz.Operation(--size); IFlyweight fu = new UnSharedConcreteFlyweight(); fu.Operation(--size); }