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)); }
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(); }
static void Main(string[] args) { RoundHole hole = new RoundHole { Radius = 15 }; SquarePegAdapter adapter = new SquarePegAdapter(new SquarePeg { Width = 10 }); if (hole.fits(adapter)) { Console.WriteLine("Кол забить можно"); } else { Console.WriteLine("Кол забить нельзя"); } }
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)); }