Exemple #1
0
        public static void Example1()
        {
            RoundHole hole = new RoundHole(5);
            RoundPeg  rPeg = new RoundPeg(5);

            /// Case 1: Ground truth :D
            if (hole.Fits(rPeg))
            {
                Console.WriteLine($"Round peg with radius {rPeg.GetRadius()} fits hole with radius {hole.GetRadius()}");
            }
            else
            {
                Console.WriteLine($"Round peg with radius {rPeg.GetRadius()} does not fit hole with radius {hole.GetRadius()}");
            }

            SquarePeg smallSQPeg = new SquarePeg(5);
            SquarePeg largeSQPeg = new SquarePeg(10);

            /// Case 2: Unmatch type
            //hole.Fits(smallSQPeg); // This won't compile (incompatible types)

            /// Case 3: Adapter
            SquarePegAdapter smallSQPegAdapter = new SquarePegAdapter(smallSQPeg);
            SquarePegAdapter largeSQPegAdapter = new SquarePegAdapter(largeSQPeg);

            Debug.Assert(hole.Fits(smallSQPegAdapter), "Unmatch adapter");
            Console.WriteLine($"Converted square peg with radius {smallSQPegAdapter.GetRadius()} fits hole with radius {hole.GetRadius()}");

            Debug.Assert(hole.Fits(largeSQPegAdapter) != false, "Suddenly match adapter");
            Console.WriteLine($"Converted square peg with radius {largeSQPegAdapter.GetRadius()} does not fit hole with radius {hole.GetRadius()}");
        }
Exemple #2
0
 public SquarePegAdapter(SquarePeg peg) : base()
 {
     this.peg = peg;
 }