Exemplo n.º 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}");
        }
        static void Main(string[] args)
        {
            RoundHole hole      = new RoundHole(5);
            SquarePeg sp        = new SquarePeg(2);
            SPAdapter spAdapter = new SPAdapter(sp.GetWidth(), sp);

            Console.WriteLine(hole.fits(spAdapter));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var hole = new RoundHole(5);
            var rpeg = new RoundPeg(5);

            Console.WriteLine("Hole Fits: " + hole.fits(rpeg));

            var small_sqpeg = new SquarePeg(5);
            var large_sqpeg = new SquarePeg(10);
            // The next line wont compile
            // Console.WriteLine("Hole Fits" + hole.fits(small_sqpeg));

            var small_sqpeg_class_adapter     = new SquarePegClassAdapter(small_sqpeg);
            var large_sqpeg_class_adapter     = new SquarePegClassAdapter(large_sqpeg);
            var small_sqpeg_Interface_adapter = new SquarePegInterfaceAdapter(small_sqpeg);
            var large_sqpeg_Interface_adapter = new SquarePegInterfaceAdapter(large_sqpeg);

            Console.WriteLine("Hole Fits: " + hole.fits(small_sqpeg_class_adapter));
            Console.WriteLine("Hole Fits: " + hole.fits(large_sqpeg_class_adapter));
            Console.WriteLine("Hole Fits: " + hole.fits(small_sqpeg_Interface_adapter));
            Console.WriteLine("Hole Fits: " + hole.fits(large_sqpeg_Interface_adapter));
        }
 public SquarePegInterfaceAdapter(SquarePeg peg)
 {
     m_peg = peg;
 }
 public SquarePegClassAdapter(SquarePeg peg)
 {
     m_peg = peg;
 }
Exemplo n.º 7
0
 public SquarePegAdapter(SquarePeg peg)
 {
     this.peg = peg;
 }
 public SPAdapter(int radius, SquarePeg sp) : base(radius)
 {
     peg = sp;
 }
 public SquarePegAdapter(SquarePeg squarePeg)
 {
     this.squarePeg = squarePeg;
 }