Example #1
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            #region 简单例子
            //var pingDiGuo = new Product("平底锅", 100);
            //var addJiangYou = new ProductDecorator("酱油", 10, pingDiGuo);
            //var addSuanCai = new ProductDecorator("老坛酸菜", 20, addJiangYou);

            //Console.WriteLine(addSuanCai.ShowProductInfo());
            #endregion

            #region Multiple Inheritance
            //var dragon = new Dragon();
            //dragon.Weight = 100;
            //dragon.Fly();
            //dragon.Crawl();
            #endregion

            #region Dynamic Decorator
            //var square = new Square(1.23f);
            //Console.WriteLine(square.AsString());

            //var redSquare = new ColorShape(square, "红色");
            //Console.WriteLine(redSquare.AsString());
            #endregion

            #region Static Decorator
            var colorShape = new ColoredShape <Square1>("红色");
            Console.WriteLine(colorShape.AsString());

            var circle = new TransparentShape <ColoredShape <Circle1> >(0.4f);
            Console.WriteLine(circle.AsString());
            #endregion
        }
Example #2
0
        static void Main(string[] args)
        {
            var redSquare = new ColoredShape <Square>("red");

            WriteLine(redSquare.AsString());

            var circle = new TransparentShape <ColoredShape <Circle> >(0.4f);

            WriteLine(circle.AsString());
        }
Example #3
0
        private static void Test2()
        {
            ColouredShape <Square> colouredShape = new ColouredShape <Square>();

            Console.WriteLine(colouredShape.AsString());

            TransparentShape <ColouredShape <Square> > transparentShape = new TransparentShape <ColouredShape <Square> >();

            Console.WriteLine(transparentShape.AsString());
        }
Example #4
0
        static void Main(string[] args)
        {
            var square = new Square(10);

            Console.WriteLine(square.AsString());

            var redSquare = new ColoredShape(square, "red");

            Console.WriteLine(redSquare.AsString());

            var redHalfTransparentSquare = new TransparentShape(redSquare, 0.5f);

            Console.WriteLine(redHalfTransparentSquare.AsString());
        }
Example #5
0
        public static void DynamicDecoratorComposition()
        {
            var square = new Square(1.23f);

            Console.WriteLine(square.AsString());

            var redSquare = new ColoredShape(square, "red");

            Console.WriteLine(redSquare.AsString());

            var redClearSquare = new TransparentShape(redSquare, 0.5f);

            Console.WriteLine(redClearSquare.AsString());
        }
Example #6
0
        static void Main(string[] args)
        {
            var square = new Square(1.23f);

            Console.WriteLine(square.AsString());

            var redSquare = new ColoredShape(square, "red");

            Console.WriteLine(redSquare.AsString());

            var redHalfTransparentSquare = new TransparentShape(redSquare, 0.5f);

            Console.WriteLine(redHalfTransparentSquare.AsString());

            // static
            ColoredShape <Circle> blueCircle = new ColoredShape <Circle>("blue");

            Console.WriteLine(blueCircle.AsString());

            TransparentShape <ColoredShape <Square> > blackHalfSquare = new TransparentShape <ColoredShape <Square> >(0.4f);

            Console.WriteLine(blackHalfSquare.AsString());
        }
Example #7
0
        // Kind of messy, don't have much control over members of deeper classes
        // Also instantiates 3 different Shapes
        public static void StaticDecoratorComposition()
        {
            var circle = new TransparentShape <ColoredShape <ShapeCircle> >();

            Console.WriteLine(circle.AsString());
        }