Exemplo n.º 1
0
        //LD_PROTOTYPE_000
        public static void RunPrototypeCreationalPattern()
        {
            Configuration c         = new Configuration();
            DateTime      startTime = DateTime.Now;

            c.GetFileInformation();  //takes long time to create the first time
            DateTime endTime = DateTime.Now;

            Console.WriteLine("First Configuration object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");

            UserProfile p = new UserProfile();

            startTime = DateTime.Now;
            p.GetDatabaseInformation();  //takes long time to create the first time
            endTime = DateTime.Now;
            Console.WriteLine("First UserProfile object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");

            //add prototypes to the manager
            PrototypeManager manager = new PrototypeManager();

            manager.AddPrototype(c, 0);
            manager.AddPrototype(p, 1);

            startTime = DateTime.Now;
            (manager.GetPrototype(0).Clone() as Configuration).ShowInformation();  //new prototype copy
            endTime = DateTime.Now;
            Console.WriteLine("Second Configuration object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");

            startTime = DateTime.Now;
            (manager.GetPrototype(1).Clone() as UserProfile).ShowInformation();  //new prototype copy
            endTime = DateTime.Now;
            Console.WriteLine("Second UserProfile object took " + endTime.Subtract(startTime).TotalSeconds + " seconds");
        }
Exemplo n.º 2
0
 protected AbstractFactory()
 {
     _manager = new PrototypeManager();
     _manager.AddPrototype("ProductA1", new ProductA1());
     _manager.AddPrototype("ProductA2", new ProductA2());
     _manager.AddPrototype("ProductB1", new ProductB1());
     _manager.AddPrototype("ProductB2", new ProductA2());
 }
Exemplo n.º 3
0
 private static void CreateManager()
 {
     _manager = new PrototypeManager();
     _manager.AddPrototype("ProductA1", new ProductA1());
     _manager.AddPrototype("ProductA2", new ProductA2());
     _manager.AddPrototype("ProductB1", new ProductB1());
     _manager.AddPrototype("ProductB2", new ProductB2());
 }
Exemplo n.º 4
0
        /// <summary>
        /// 原型管理器
        /// </summary>
        static void PrototypeManager()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //创建原型管理器
            PrototypeManager prototypeManager = new PrototypeManager();

            stopwatch.Stop();
            Console.WriteLine($"原型管理器{Environment.NewLine}-------------------------------------------");
            Console.WriteLine($"Load用时:{stopwatch.Elapsed.TotalMilliseconds}ms");
            stopwatch.Restart();

            //创建实例
            Kit kit = prototypeManager.CreateInstance("LogitechKit") as Kit;

            stopwatch.Stop();
            Console.WriteLine($"CreateInstance用时:{stopwatch.Elapsed.TotalMilliseconds}ms");
            Console.WriteLine($"当前套装内的鼠标是:{kit.Mouse.GetBrand()}");
            Console.WriteLine($"当前套装内的键盘是:{kit.Keyboard.GetBrand()}");

            //创建原型并添加至原型管理器
            Kit razeKit = new Kit();

            razeKit.Mouse    = new RazeMouse();
            razeKit.Keyboard = new RazeKeyboard();
            prototypeManager.AddPrototype("RazeKit", razeKit);
            Console.ReadKey();
        }
Exemplo n.º 5
0
 private void LoadPrototypes()
 {
     PrototypeManager.AddPrototype("Factories");
     PrototypeManager.AddPrototype("Trucks");
 }