Пример #1
0
        internal static void Main(string[] args)
        {
            var squarePeg       = new SquarePeg(width: 5.0);       // First we create a square peg
            var roundPegAdapter = new RoundPegAdapter(squarePeg);  // Then we wrap the square peg with an adapter
            var actualRoundPeg  = new ActualRoundPeg(radius: 2);   // Here we've created a round peg just for kicks

            var roundHole = new RoundHole(roundPegAdapter.Radius); // We construct the round hole such that it will perfectly fit the roundPegAdapter

            roundHole.Insert(actualRoundPeg);                      // Of course we can insert an actual round peg
            roundHole.Insert(roundPegAdapter);                     // And with the adapter pattern, we can insert a square peg too, as long as we wrap it with the adapter first

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Create some pegs.
            RoundPeg roundPeg = new RoundPeg();
            SquarePeg squarePeg = new SquarePeg();

            // Do an insert using the square peg.
            squarePeg.Insert("Inserting square peg...");
            
            // Create a two-way adapter and do an insert with it.
            ISquarePeg roundToSquare = new PegAdapter(roundPeg);
            roundToSquare.Insert("Inserting round peg...");

            // Do an insert using the round peg.
            roundPeg.InsertIntoHole("Inserting round peg...");

            // Create a two-way adapter and do an insert with it.
            IRoundPeg squareToRound = new PegAdapter(squarePeg);
            squareToRound.InsertIntoHole("Inserting square peg...");

            Console.ReadKey();
        }
Пример #3
0
 /// <summary>
 /// Constructs the <see cref="RoundPegAdapter"/> with a <see cref="SquarePeg"/>.
 /// </summary>
 public RoundPegAdapter(SquarePeg squarePeg)
 {
     this.squarePeg = squarePeg;
 }
Пример #4
0
 public PegAdapter(SquarePeg squarePeg)
 {
     _squarePeg = squarePeg;
 }