static void Main(string[] args) { RoundPeg RP = new RoundPeg(6); SquarePeg SP = new SquarePeg(5); ConsoleApp1.Source.Adapter.Adapter A = new ConsoleApp1.Source.Adapter.Adapter(SP); RoundHole RH = new RoundHole(7); Console.WriteLine(RH.fits(A)); }
public void RoundHole_Case_Fits() { double radius = 4; var roundPeg = new RoundPeg(radius); var roundHole = new RoundHole(radius); bool fit = roundHole.Fits(roundPeg); Assert.True(fit); }
static void Main(string[] args) { RoundHole roundHole = new RoundHole(12.0); IRaundPeg raundPeg = new RaundPeg.RaundPeg(10.0); SquarePeg.SquarePeg squarePeg = new SquarePeg.SquarePeg(16.0); SquarePegAdapter squarePegAdapter = new SquarePegAdapter(squarePeg); Console.WriteLine(roundHole.fits(raundPeg)); Console.WriteLine(roundHole.fits(squarePegAdapter)); }
public void Run() { RoundHole rh = new RoundHole(5); RoundPeg rp = new RoundPeg(4); rh.Put(rp); SquarePeg sp = new SquarePeg(1); RoundPeg str = new SquareToRound(sp); rh.Put(str); }
public static void Test() { RoundHole hole = new RoundHole(5); RoundPeg peg = new RoundPeg(5); System.Console.WriteLine(hole.Fits(peg)); SquarePeg smallSquare = new SquarePeg(5); SquarePeg largeSquare = new SquarePeg(10); //System.Console.WriteLine(hole.Fits(smallSquare)); SquarePegAdapter smallSquareAdapter = new SquarePegAdapter(smallSquare); SquarePegAdapter largeSquareAdapter = new SquarePegAdapter(largeSquare); System.Console.WriteLine(hole.Fits(smallSquareAdapter)); System.Console.WriteLine(hole.Fits(largeSquareAdapter)); }
static void Main() { // EN: Round fits round, no surprise. // // RU: Круглое к круглому — всё работает. RoundHole hole = new RoundHole(5); RoundPeg rpeg = new RoundPeg(5); if (hole.Fits(rpeg)) { Console.WriteLine("Round peg r5 fits round hole r5."); } SquarePeg smallSqPeg = new SquarePeg(2); SquarePeg largeSqPeg = new SquarePeg(20); // EN: hole.fits(smallSqPeg); // Won't compile. // // RU: hole.fits(smallSqPeg); // Не скомпилируется. // EN: Adapter solves the problem. // // RU: Адаптер решит проблему. SquarePegAdapter smallSqPegAdapter = new SquarePegAdapter(smallSqPeg); SquarePegAdapter largeSqPegAdapter = new SquarePegAdapter(largeSqPeg); if (hole.Fits(smallSqPegAdapter)) { Console.WriteLine("Square peg w2 fits round hole r5."); } if (hole.Fits(largeSqPegAdapter)) { Console.WriteLine("Square peg w20 does not fit into round hole r5."); } Console.ReadKey(); }
static void Main(string[] args) { #region FactoryMethod ITransport passengerTransport = new PassengerLogistics().CreateTransport(); ITransport seaTransport = new SeaLogistics().CreateTransport(); ITransport roadTransport = new RoadLogistics().CreateTransport(); passengerTransport.Delivery += PrintEvent; seaTransport.Delivery += PrintEvent; roadTransport.Delivery += PrintEvent; passengerTransport.Transporting(); seaTransport.Transporting(); roadTransport.Transporting(); #endregion #region AbstractFactory if (args[0] == "Windows") { IGuiElement element = new CreatorWinElements(); GuiMaster master = new GuiMaster(element); master.CreateElements(); master.Paint(); } if (args[0] == "Mac") { IGuiElement element = new CreatorMacElements(); GuiMaster master = new GuiMaster(element); master.CreateElements(); master.Paint(); } else { throw new FormatException(nameof(args)); } #endregion #region Builder CarBuilder builder = new CarBuilder(); Director director = new Director(builder); Car car = builder.GetResult(); Console.WriteLine(director.ToString()); CarManualBuilder manualBuilder = new CarManualBuilder(); director = new Director(manualBuilder); Manual manual = manualBuilder.GetResult(); car.Reset(); Console.WriteLine(director.ToString()); manual.Reset(); #endregion #region Prototype //массив фигур Shape[] shapes = new Shape[3]; //создаем фигуры Triangle triangle = new Triangle(12.4, 12.4); Rectangle rectangle = new Rectangle(5, 10, "Grey", true); Circle circle = new Circle(256.6, true, "Red"); //кладём в массив shapes.SetValue(triangle, 0); shapes.SetValue(circle, 1); shapes.SetValue(rectangle, 2); //создаем копии List <Shape> shapesCopy = new List <Shape>(shapes.Length); foreach (Shape shape in shapes) { shapesCopy.Add(shape.Clone()); } #endregion #region Singleton DataBase db = DataBase.GetInstance(); db.Query("SELECT ..."); #endregion #region Adapter RoundHole hole = new RoundHole(125.5); RoundPeg peg = new RoundPeg(175); hole.Fits(peg); var smallSqpeg = new SquarePage(2); var largeSqpeg = new SquarePage(5); //hole.Fits(small_sqpeg) // ошибка компиляции, несовместимые типы var smallSqpegAdapter = new SquarePegAdapter(smallSqpeg); var largeSqpegAdapter = new SquarePegAdapter(largeSqpeg); hole.Fits(smallSqpegAdapter); hole.Fits(largeSqpegAdapter); #endregion #region Bridge var tv = new Tv(); var remote = new AdvancedRemote(tv); remote.TooglePower(); var radio = new Radio(); var remoting = new Remote(radio); remoting.ChannelDown(); #endregion #region Composite var all = new CompoundGraphic(); all.Add(new Dot(1, 1)); all.Add(new structure_patterns.Composite.Circle(5, 3, 10.5)); var group = new CompoundGraphic(); group.Add(new structure_patterns.Composite.Circle(1, 1, 135.4)); group.Add(new Dot(15, 15)); all.Add(group); all.Draw(); #endregion #region Decorator var source = new FileDataSource("somefile.dat"); source.WriteData("salaryrecords"); var decorator = new CompressionDecorator(source); source.WriteData("salaryrecords"); decorator.Compression(); #endregion #region Facade var converter = new VideoConverter(); var mp4 = converter.Convert("youtubevideo.org", "mp4"); var fileStream = mp4.OpenRead(); fileStream.Lock(1, 1); #endregion #region Cache Forest forest = new Forest(); forest.PlantTree(1, 1, "green", "apple", "textture nature"); forest.PlantTree(2, 1, "green", "pineapple", "nature"); forest.Draw(new object()); #endregion #region Proxy var service = new ThirdPartyYoutubeClass(); var proxy = new CachedYoutubeClass(service); var manager = new YoutubeManager(proxy); manager.ReactOnUserInput(123); #endregion #region ChainOfResponsibility var dialog = new Dialog("Help Me from Dialog"); var panel = new Panel("Help me from Panel"); var ok = new Button("Button Ok help text"); var cancel = new Button("Button canceled help text"); panel.Add(ok); panel.Add(cancel); dialog.Add(panel); dialog.ShowHelp(); #endregion }