Esempio n. 1
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();
        }