Пример #1
0
        static void Main(string[] args)
        {
            CompoundGraphic root = new CompoundGraphic();

            root.Add(new Dot(0, 0));
            root.Add(new Dot(1, 1));
            root.Move(2, 2);

            CompoundGraphic comp = new CompoundGraphic();

            comp.Add(new Dot(3, 3));
            comp.Add(new Dot(4, 4));
            root.Add(comp);
            root.Add(new Dot(5, 5));

            CompoundGraphic circleComp = new CompoundGraphic();

            circleComp.Add(new Circle(3, 3, 3));
            circleComp.Draw(); //not draw circle why?

            Dot d = new Dot(6, 6);

            root.Add(d);
            root.Remove(d);
        }
Пример #2
0
        static void Main()
        {
            var graphic = new CompoundGraphic();

            graphic.Add(new Point(3, 4));
            graphic.Add(new Point(4, 1));
            graphic.Add(new Point(8, 1));

            graphic.Move(1, 1);

            graphic.Draw();
        }
Пример #3
0
        public IEnumerable <string> DrawStuff()
        {
            List <string> _events = new List <string>();

            void AddToEventLog(object sender, string e)
            {
                _events.Add(e);
            }

            /*
             *
             * compound0___________
             |                   |
             | compound1__         compound2_____
             |          |        |             |
             | dot1       circle   compound3     dot2
             |
             |                   circle2
             */

            // Setup

            var dot1    = new Dot(3, 4);
            var dot2    = new Dot(0, 0);
            var circle  = new Circle(5, 6, 100);
            var circle2 = new Circle(55, 66, 77);

            var compound0 = new CompoundGraphic();
            var compound1 = new CompoundGraphic();
            var compound2 = new CompoundGraphic();
            var compound3 = new CompoundGraphic();

            compound1.Add(dot1, circle);
            compound2.Add(compound3, dot2);
            compound3.Add(circle2);
            compound0.Add(compound1, compound2);

            dot1.OnDraw    += AddToEventLog;
            dot2.OnDraw    += AddToEventLog;
            circle.OnDraw  += AddToEventLog;
            circle2.OnDraw += AddToEventLog;

            // Action

            dot1.Draw();
            circle.Move(20, 30);
            circle.Draw();

            compound0.Move(500, 600);
            compound0.Draw();

            return(_events);
        }
Пример #4
0
        static void Main(string[] args)
        {
            #region FactoryMethod

            ITransport passengerTransport = new PassengerLogistics().CreateTransport();
            ITransport seaTransport       = new SeaLogistics().CreateTransport();
            ITransport roadTransport      = new RoadLogistics().CreateTransport();
            passengerTransport.Delivery += PrintEvent;
            seaTransport.Delivery       += PrintEvent;
            roadTransport.Delivery      += PrintEvent;
            passengerTransport.Transporting();
            seaTransport.Transporting();
            roadTransport.Transporting();

            #endregion

            #region AbstractFactory

            if (args[0] == "Windows")
            {
                IGuiElement element = new CreatorWinElements();

                GuiMaster master = new GuiMaster(element);
                master.CreateElements();
                master.Paint();
            }

            if (args[0] == "Mac")
            {
                IGuiElement element = new CreatorMacElements();

                GuiMaster master = new GuiMaster(element);
                master.CreateElements();
                master.Paint();
            }
            else
            {
                throw new FormatException(nameof(args));
            }

            #endregion

            #region Builder

            CarBuilder builder  = new CarBuilder();
            Director   director = new Director(builder);
            Car        car      = builder.GetResult();
            Console.WriteLine(director.ToString());
            CarManualBuilder manualBuilder = new CarManualBuilder();
            director = new Director(manualBuilder);
            Manual manual = manualBuilder.GetResult();
            car.Reset();
            Console.WriteLine(director.ToString());
            manual.Reset();

            #endregion

            #region Prototype

            //массив фигур
            Shape[] shapes = new Shape[3];
            //создаем фигуры
            Triangle  triangle  = new Triangle(12.4, 12.4);
            Rectangle rectangle = new Rectangle(5, 10, "Grey", true);
            Circle    circle    = new Circle(256.6, true, "Red");
            //кладём в массив
            shapes.SetValue(triangle, 0);
            shapes.SetValue(circle, 1);
            shapes.SetValue(rectangle, 2);

            //создаем копии
            List <Shape> shapesCopy = new List <Shape>(shapes.Length);
            foreach (Shape shape in shapes)
            {
                shapesCopy.Add(shape.Clone());
            }
            #endregion

            #region Singleton

            DataBase db = DataBase.GetInstance();
            db.Query("SELECT ...");

            #endregion

            #region Adapter
            RoundHole hole = new RoundHole(125.5);
            RoundPeg  peg  = new RoundPeg(175);
            hole.Fits(peg);

            var smallSqpeg = new SquarePage(2);
            var largeSqpeg = new SquarePage(5);
            //hole.Fits(small_sqpeg) // ошибка компиляции, несовместимые типы
            var smallSqpegAdapter = new SquarePegAdapter(smallSqpeg);
            var largeSqpegAdapter = new SquarePegAdapter(largeSqpeg);
            hole.Fits(smallSqpegAdapter);
            hole.Fits(largeSqpegAdapter);

            #endregion

            #region Bridge

            var tv     = new Tv();
            var remote = new AdvancedRemote(tv);
            remote.TooglePower();

            var radio    = new Radio();
            var remoting = new Remote(radio);
            remoting.ChannelDown();
            #endregion

            #region Composite

            var all = new CompoundGraphic();
            all.Add(new Dot(1, 1));
            all.Add(new structure_patterns.Composite.Circle(5, 3, 10.5));

            var group = new CompoundGraphic();
            group.Add(new structure_patterns.Composite.Circle(1, 1, 135.4));
            group.Add(new Dot(15, 15));
            all.Add(group);

            all.Draw();

            #endregion

            #region Decorator

            var source = new FileDataSource("somefile.dat");
            source.WriteData("salaryrecords");
            var decorator = new CompressionDecorator(source);
            source.WriteData("salaryrecords");
            decorator.Compression();

            #endregion

            #region Facade

            var converter  = new VideoConverter();
            var mp4        = converter.Convert("youtubevideo.org", "mp4");
            var fileStream = mp4.OpenRead();
            fileStream.Lock(1, 1);
            #endregion

            #region Cache
            Forest forest = new Forest();
            forest.PlantTree(1, 1, "green", "apple", "textture nature");
            forest.PlantTree(2, 1, "green", "pineapple", "nature");
            forest.Draw(new object());
            #endregion

            #region Proxy

            var service = new ThirdPartyYoutubeClass();
            var proxy   = new CachedYoutubeClass(service);
            var manager = new YoutubeManager(proxy);
            manager.ReactOnUserInput(123);

            #endregion

            #region ChainOfResponsibility

            var dialog = new Dialog("Help Me from Dialog");
            var panel  = new Panel("Help me from Panel");
            var ok     = new Button("Button Ok help text");
            var cancel = new Button("Button canceled help text");
            panel.Add(ok);
            panel.Add(cancel);
            dialog.Add(panel);
            dialog.ShowHelp();
            #endregion
        }