Esempio n. 1
0
 public BananaAdapter(Banana banana)
 {
     if (banana != null)
     {
         this.adapteeBanana = banana;
     }
     else
     {
         throw new ArgumentNullException("Value cannot be null.");
     }
 }
Esempio n. 2
0
        private static void PrintInfoForStructuralPatterns()
        {
            // Facade Test
            WriteTitleToConsole("Facade Test");
            string iniFilePath = @"../../StructuralPatterns/FacadeExample/IniFileTestExample/MyConfig.ini";
            var ini = new IniFile(iniFilePath);
            ini.WriteValue("System", "Version", "1.1");
            ini.WriteValue("System", "Type", "Free License");
            var typeValue = ini.ReadValue("System", "Type");
            Console.WriteLine(typeValue);

            // Composide Test
            WriteTitleToConsole("\nComposide Test");
            var mayor = new Director("Chomakov", 7800.0, 8);
            var employees = new List<CityHallEmployee>()
            {
               new CityHallEmployee( "George Gergov", 5000000, "Svinepas"),
               new CityHallEmployee( "Stefan Pavlov", 438, "Economy"),
               new CityHallEmployee( "Ana Vasileva", 450, "English Teacher"),
            };
            mayor.Employees.AddRange(employees);

            mayor.FireEmployee("Ana Vasileva");
            var employee = new CityHallEmployee("Pesho The Dragon", 1700, "Lover Level 5");
            mayor.HiresEmployee(employee);

            mayor.PrintEmployeeInformation();

            // Proxy Test
            WriteTitleToConsole("\nProxy Test");
            var email = new EmailProxy();
            var username = @"master";
            var password = "******";//"5654<f";
            email.GoIn(username, password);

            // Decorator Test
            WriteTitleToConsole("\nDecorator Test");
            var burger = new Burger();
            Console.WriteLine("Burger:\nDescription: {0}.\nPrice: {1}.", burger.Description, burger.Cost);

            var donkeyBurger = new DonkeyBurger(burger);
            donkeyBurger.printInfo();

            var burgerWithSauces = new MayonnaiseDecorator(new KetchupDecorator(burger));
            Console.WriteLine("Burger with sauces:\nDescription: {0}.\nPrice: {1}.",
                                        burgerWithSauces.Description, burgerWithSauces.Cost);

            // Adapter Test
            WriteTitleToConsole("\nAdapter Test");
            var banana = new Banana();
            banana.ShowAllBananaInformation();
            var bananaAdapter = new BananaAdapter(banana);
            bananaAdapter.PrintInfo();

            // Bridge Test
            WriteTitleToConsole("\nBridge Test");
            var page3Diploma = new Diploma(new PageA3());
            page3Diploma.Print();
            var page4Certificate = new Certificate(new PageA4());
            page4Certificate.Print();

            // Flyweight Test
            WriteTitleToConsole("\nFlyweight Test");
            var shapeFactory = new ShapeFactory();
            var asteriskRect = shapeFactory.GetShape(ShapeType.Triangle);
            var numberSignRect = shapeFactory.GetShape(ShapeType.Triangle);

            asteriskRect.SetSymbol('*');
            asteriskRect.Draw();

            numberSignRect.SetSymbol('#');
            numberSignRect.Draw();

            Console.WriteLine("Are the addresses in memory equal: {0}", object.ReferenceEquals(asteriskRect, numberSignRect));
        }