/// <summary> /// 享元模式 /// </summary> /// <param name="args"></param> static void Main(string[] args) { WebSiteFactory f = new WebSiteFactory(); WebSite fx = f.GetWebSiteCategory("产品展示"); fx.Use(new User("菜鸟")); WebSite fy = f.GetWebSiteCategory("产品展示"); fy.Use(new User("菜鸟2")); WebSite fz = f.GetWebSiteCategory("博客"); fz.Use(new User("南海鳄神")); Console.WriteLine("网站类别数量为:" + f.GetWebSiteCount()); Console.Read(); }
static void Main(string[] args) { try { {//BasicStructure int extrinsicState = 22; FlyweightFactory flyweightFactory = new FlyweightFactory(); var flyweight = flyweightFactory.GetFlyweight("X"); flyweight.Operation(--extrinsicState); flyweight = flyweightFactory.GetFlyweight("Y"); flyweight.Operation(--extrinsicState); flyweight = flyweightFactory.GetFlyweight("Z"); flyweight.Operation(--extrinsicState); UnSharedConcreteFlyweight uf = new UnSharedConcreteFlyweight(); uf.Operation(--extrinsicState); } {//SituationSimulation WebSiteFactory webSiteFactory = new WebSiteFactory(); var fx = webSiteFactory.GetWebSiteCategory("产品展示"); fx.Use(); var fy = webSiteFactory.GetWebSiteCategory("产品展示"); fy.Use(); var fz = webSiteFactory.GetWebSiteCategory("产品展示"); fz.Use(); var fl = webSiteFactory.GetWebSiteCategory("博客"); fl.Use(); var fm = webSiteFactory.GetWebSiteCategory("博客"); fm.Use(); var fn = webSiteFactory.GetWebSiteCategory("博客"); fn.Use(); Console.WriteLine($"网站分类总数为:{webSiteFactory.GetWebSiteCount()}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }