Example #1
0
        static void Main(string[] args)
        {
            // Example 1: Peg & Hole
            var roundPeg  = new RoundPeg(5);
            var roundHole = new RoundHole(7);

            Console.WriteLine($"The round peg fits the round hole: {roundHole.Fits(roundPeg)}");

            var squarePeg = new SquarePeg(10);
            // This returns an error because cannot convert
            // Console.WriteLine($"The square peg fits the round hole: {roundHole.Fits(squarePeg)}");

            var squarePegAdapter = new SquarePegAdapter(squarePeg);

            Console.WriteLine($"The square peg fits the round hole: {roundHole.Fits(squarePegAdapter)}");

            // Example 2
            Draw();
        }
Example #2
0
 public SquarePegAdapter(SquarePeg squarePeg)
 {
     this.squarePeg = squarePeg;
 }