Beispiel #1
0
        public void Visit(Rectangle rectangle)
        {
            var pen   = new Pen(Color);
            var image = new Bitmap(500, 500);
            var g     = Graphics.FromImage(image);

            g.DrawRectangle(pen, X, Y, rectangle.Width, rectangle.Height);
            g.DrawImage(image, 0, 0);
            Console.WriteLine("Draw " + rectangle.Name);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var triangle  = new Triangle(3, 4, 5);
            var rectangle = new Rectangle(4, 5);
            var circle    = new Circle(3);
            var figures   = new List <Figure> {
                triangle, rectangle, circle
            };

            var perimeterVisitor = new PerimeterVisitor();
            var areaVisitor      = new AreaVisitor();
            var drawVisitor      = new DrawVisitor(100, 100, Color.Orchid);

            foreach (var figure in figures)
            {
                figure.Accept(perimeterVisitor);
                figure.Accept(areaVisitor);
                figure.Accept(drawVisitor);
            }
        }