示例#1
0
        static void Main(string[] args)
        {
            var    hole     = new RoundHole(5);
            IRound roundPeg = new RoundPeg(5);

            System.Console.WriteLine($"Round hole radius is : {hole.Radius}");
            System.Console.WriteLine($"Round peg radius is : {roundPeg.Radius}");

            bool response = hole.Fits(roundPeg);

            System.Console.WriteLine($"Fits? : {response}");

            ISquare small_sqpeg = new SquarePeg(5);
            ISquare large_sqpeg = new SquarePeg(10);

            System.Console.WriteLine($"Small square peg with is : {small_sqpeg.Width}");
            System.Console.WriteLine($"Large square peg with is : {large_sqpeg.Width}");

            // hole.Fits(small_sqpeg); this won't compile (incompatible types)
            var small_sqpeg_adapter = new SquarePegAdapter(small_sqpeg);
            var large_sqpeg_adapter = new SquarePegAdapter(large_sqpeg);

            System.Console.WriteLine($"Small square peg adapter radious is: {small_sqpeg_adapter.Radius}");
            System.Console.WriteLine($"Large square peg adapter radious is: {large_sqpeg_adapter.Radius}");

            response = hole.Fits(small_sqpeg_adapter);
            System.Console.WriteLine($"Fits? : {response}");

            response = hole.Fits(large_sqpeg_adapter);
            System.Console.WriteLine($"Fits? : {response}");
        }
示例#2
0
        static void Main(string[] args)
        {
            RoundHole roundHole = new RoundHole(10);

            IRoundable roundPeg  = new RoundPeg(11);
            SquarePeg  squarePeg = new SquarePeg(14);

            IRoundable squarePegAdapter = new SquarePegAdapter(squarePeg);

            Console.WriteLine(roundHole.Fits(roundPeg));
            Console.WriteLine(roundHole.Fits(squarePegAdapter));
        }
示例#3
0
        private static void Main(string[] args)
        {
            RoundHole  round      = new RoundHole(22);
            RoundThing roundThing = new RoundThing {
                Radius = 10
            };

            SquareThing squareThing = new SquareThing {
                Width = 21
            };

            Console.WriteLine(round.Fits(roundThing));
            Console.WriteLine(round.Fits(new SquareThingAdapter(squareThing)));
            Console.ReadKey();
        }