コード例 #1
0
        public static void FactoryInterfaceExample()
        {
            Console.WriteLine("1. Circle\n2. Square\n3. Rectangle");
            var choice = Convert.ToInt32(Console.ReadLine());

            interfaces.IDrawing drawingObj;

            switch (choice)
            {
            case 1:
                drawingObj = new interfaces.Cirle();
                break;

            case 2:
                drawingObj = new interfaces.Square();
                break;

            case 3:
                drawingObj = new interfaces.Rectangle();
                break;

            //case 4:
            //    drawingObj = new Triangle();
            //    break;
            default:
                return;

                break;
            }

            drawingObj.TakeInput();
            Console.WriteLine("Area = >" + drawingObj.Area());
            Console.WriteLine("Perimeter = >" + drawingObj.Perimeter());
        }
コード例 #2
0
        public static void InterfaceExplained()
        {
            var squareObj = new interfaces.Square();

            interfaces.IArea areaInt = squareObj;

            var circleObj = new interfaces.Cirle();

            //circleObj.Add();
            areaInt = circleObj;


            interfaces.IPerimeter perimeterInt = circleObj;
            perimeterInt = squareObj;

            interfaces.IDrawing drawingInt = squareObj;
        }