Beispiel #1
0
        static void Main(string[] args)
        {
            Developer dev    = new PanelDeveloper("Some big company");
            House     house2 = dev.Create();

            dev = new WoodDeveloper("Private Developer");
            House house = dev.Create();

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Factory Method
            Developer dev    = new PanelDeveloper("ООО КирпичСтрой");
            House     house2 = dev.Create();

            dev = new WoodDeveloper("Частный застройщик");
            House house = dev.Create();

            Console.ReadLine();



            //Abstract Factory
            Hero elf = new Hero(new ElfFactory());

            elf.Hit();
            elf.Run();

            Hero voin = new Hero(new VoinFactory());

            voin.Hit();
            voin.Run();

            Console.ReadLine();



            //Prototype
            IFigure figure       = new Rectangle(30, 40);
            IFigure clonedFigure = figure.Clone();

            figure.GetInfo();
            clonedFigure.GetInfo();

            figure       = new Circle(30);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();

            Console.Read();


            //Builder
            // содаем объект пекаря
            Baker baker = new Baker();
            // создаем билдер для ржаного хлеба
            BreadBuilder builder = new RyeBreadBuilder();
            // выпекаем
            Bread ryeBread = baker.Bake(builder);

            Console.WriteLine(ryeBread.ToString());
            // оздаем билдер для пшеничного хлеба
            builder = new WheatBreadBuilder();
            Bread wheatBread = baker.Bake(builder);

            Console.WriteLine(wheatBread.ToString());

            Console.Read();

            //Strategy
            Car auto = new Car(4, "Volvo", new PetrolMove());

            auto.Move();
            auto.Movable = new ElectricMove();
            auto.Move();

            Console.ReadLine();

            //Observer
            Stock  stock  = new Stock();
            Bank   bank   = new Bank("ЮнитБанк", stock);
            Broker broker = new Broker("Иван Иваныч", stock);

            // имитация торгов
            stock.Market();
            // брокер прекращает наблюдать за торгами
            broker.StopTrade();
            // имитация торгов
            stock.Market();

            Console.Read();



            //Command
            Pult pult = new Pult();
            TV   tv   = new TV();

            pult.SetCommand(new TVOnCommand(tv));
            pult.PressButton();
            pult.PressUndo();

            Console.Read();



            //Iterator
            Library library = new Library();
            Reader  reader  = new Reader();

            reader.SeeBooks(library);

            Console.Read();



            //State
            Water water = new Water(new LiquidWaterState());

            water.Heat();
            water.Frost();
            water.Frost();

            Console.Read();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            #region Creational

            #region FactoryMethod
            Console.WriteLine("FactoryMethod:");
            DeveloperAbsract dev    = new PanelDeveloper("ООО КирпичСтрой");
            HouseAbsctract   house2 = dev.Create();

            dev = new WoodDeveloper("Частный застройщик");
            HouseAbsctract house = dev.Create();
            Console.WriteLine("");
            #endregion


            #region Abstract Factory
            Console.WriteLine("Abstract Factory:");

            Hero elf = new Hero(new ElfFactory());
            elf.Hit();
            elf.Run();

            Hero voin = new Hero(new VoinFactory());
            voin.Hit();
            voin.Run();

            Console.WriteLine("");
            #endregion

            #region Prototype
            Console.WriteLine("Prototype:");

            Console.WriteLine("1. Copy: ");
            IFigure figure       = new Rectangle(30, 40);
            IFigure clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();

            figure       = new Circle(30, 10, 20);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();

            Console.WriteLine("2. Copy 2: ");
            Circle clonedFigure2 = figure.Clone2() as Circle;
            clonedFigure2.Point.X = 50;
            clonedFigure2.Point.X = 60;
            figure.GetInfo();
            clonedFigure2.GetInfo();

            Console.WriteLine("3. DeepCopy: ");
            figure = new Circle(50, 100, 200);
            Circle clonedFigure3 = figure.DeepCopy() as Circle;
            clonedFigure2.Point.X = 10;
            clonedFigure2.Point.X = 10;
            figure.GetInfo();
            clonedFigure2.GetInfo();

            Console.WriteLine("");
            #endregion

            #endregion

            Console.ReadLine();
        }