public static void Main(string[] args) { #region Observer Pattern Book b = new Book("The lord of the rings"); var l = new Librarian(); var g = new Grocer(); var r = new Restorer(); b.addObserver(l); b.addObserver(g); b.addObserver(r); b.Notify(); Console.WriteLine("---------------------------------------------------------"); #endregion #region Factory Method Pattern MyApplication app = new MyApplication(); var doc = app.createDocument(); doc.Open(); Console.WriteLine("---------------------------------------------------------"); #endregion #region Bridge Pattern AbstractPicture img = new JPG(new OSXImp()); img.Caller(); img = new BMP(new WinImp()); img.Caller(); img = new GIF(new LinuxImp()); img.Caller(); Console.WriteLine("---------------------------------------------------------"); #endregion #region Abstract Factory Pattern // THIS IS THE CLIENT CLASS CONTENT MENTIONED ON PATTERN PRINCIPLES. IFactory factory = new PMFactory(); IScrollbar scrollbar = factory.BuildScrollbar(); IWindow window = factory.BuildWindow(); scrollbar.Draw(); window.Draw(); Console.WriteLine("\n"); factory = new MOTIFFactory(); scrollbar = factory.BuildScrollbar(); window = factory.BuildWindow(); scrollbar.Draw(); window.Draw(); Console.WriteLine("---------------------------------------------------------"); #endregion #region Adapter Pattern var oldcar = new OldCar("Chevrolet", "Impala", new DateTime(1967, 1, 1)); var adapter = new OldNewAdapter(oldcar); Console.WriteLine(adapter.getBrand()); Console.WriteLine(adapter.getYears()); Console.WriteLine("---------------------------------------------------------"); #endregion }
public void CrearAndroid() { factory = new AndroidFactory(); IButton button = factory.CrearButton("Registrarse"); IScrollbar scrollbar = factory.CrearScrollbar(); ITextField textField = factory.CrearTextfield(); Assert.IsTrue(button is ButtonAndroid); Assert.IsTrue(scrollbar is ScrollbarAndroid); Assert.IsTrue(textField is TextFieldAndroid); Assert.AreEqual($"Android: Ejecutando Registrarse.", button.Presionar()); Assert.AreEqual($"Android: Bajando", scrollbar.Bajar()); char letra = 'x'; Assert.AreEqual($"Android: Input <{letra}>", textField.Escribir(letra)); }
public void CrearIOS() { factory = new IOSFactory(); IButton button = factory.CrearButton("Enviar"); IScrollbar scrollbar = factory.CrearScrollbar(); ITextField textField = factory.CrearTextfield(); Assert.IsTrue(button is ButtonIOS); Assert.IsTrue(scrollbar is ScrollbarIOS); Assert.IsTrue(textField is TextFieldIOS); Assert.AreEqual($"IOS: Ejecutando Enviar.", button.Presionar()); Assert.AreEqual($"IOS: Bajando", scrollbar.Bajar()); char letra = 'm'; Assert.AreEqual($"IOS: Input <{letra}>", textField.Escribir(letra)); }
public void CrearWeb() { factory = new WebFactory(); IButton button = factory.CrearButton("Iniciar Sesion"); IScrollbar scrollbar = factory.CrearScrollbar(); ITextField textField = factory.CrearTextfield(); Assert.IsTrue(button is ButtonWeb); Assert.IsTrue(scrollbar is ScrollbarWeb); Assert.IsTrue(textField is TextFieldWeb); Assert.AreEqual($"JavaScript: Ejecutando Iniciar Sesion.", button.Presionar()); Assert.AreEqual($"JavaScript: Bajando", scrollbar.Bajar()); char letra = 'a'; Assert.AreEqual($"JavaScript: Input <{letra}>", textField.Escribir(letra)); }