static void Main(string[] args)
        {
            //sample 2
            //var repo = new DepartmentRepository();
            //var department1 = repo.GetDepartment(1);

            //var department2 = repo.GetDepartment(1);

            //Console.WriteLine(department1.GetHashCode() == department2.GetHashCode());

            //sample 1
            FlyWeightFactory flyWeightFactory = new FlyWeightFactory();

            IAlphabet alphabet = flyWeightFactory.GetObject(typeof(A).Name);

            alphabet.Render("Arial");
            Console.WriteLine();

            alphabet = flyWeightFactory.GetObject(typeof(B).Name);
            alphabet.Render("Tahoma");
            Console.WriteLine();

            alphabet = flyWeightFactory.GetObject(typeof(A).Name);
            alphabet.Render("Time is New Roman");
            Console.WriteLine();

            alphabet = flyWeightFactory.GetObject(typeof(A).Name);
            alphabet.Render("B Nazanin");
            Console.WriteLine();

            Console.WriteLine("Total new alphabet count:" + flyWeightFactory.Count);


            Console.ReadKey();
        }
Beispiel #2
0
 static void PrintSequense(string seq)
 {
     foreach (char c in seq)
     {
         for (int i = 0; i < VeryHeavyObject.MAX_SIZE; i++)
         {
             Console.WriteLine(FlyWeightFactory.GetHeavyObjects(c)[i]);
         }
     }
 }
Beispiel #3
0
 static void PrintDigits(string number, string pow)
 {
     foreach (int c in number)
     {
         for (int i = 0; i < VeryHeavyObject.MAX_SIZE; i++)
         {
             Console.WriteLine(FlyWeightFactory.GetHeavyObjects(c)[i]);
         }
     }
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            int state = 0;

            FlyWeightFactory f  = new FlyWeightFactory();
            FlyWeight        fx = f.GetFlyWeight("X");

            fx.Operation(++state);
            FlyWeight fy = f.GetFlyWeight("Y");

            fy.Operation(++state);
            FlyWeight fz = f.GetFlyWeight("Z");

            fz.Operation(++state);
            Console.ReadKey();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //享元模式

            int extrinsicState    = 22;
            FlyWeightFactory fact = new FlyWeightFactory();
            Flyweight        fx   = fact.GetFlayWeight("x");

            fx.Operation(--extrinsicState);

            Flyweight fy = fact.GetFlayWeight("y");

            fy.Operation(--extrinsicState);

            Flyweight fz = fact.GetFlayWeight("z");

            fz.Operation(--extrinsicState);


            UnSharedConcreteFlyweight unsharedFlyweight = new UnSharedConcreteFlyweight();

            unsharedFlyweight.Operation(--extrinsicState);


            Console.WriteLine("********************************************");


            WebSiteFactory wf = new WebSiteFactory();
            WebSiteClass   wc = wf.getWebSiteCategory("产品展示");

            wc.Use(new User("小鸟"));

            WebSiteClass wc1 = wf.getWebSiteCategory("产品展示");

            wc.Use(new User("大鸟"));


            WebSiteClass bg = wf.getWebSiteCategory("博客");

            wc.Use(new User("科技"));

            Console.Read();
        }
        static void Main(string[] args)
        {
            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);

            UnsharedConcreteFlyweight fu = new UnsharedConcreteFlyweight();

            fu.Operation(--extrinsicstate);

            Console.ReadKey();
        }