示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("USING INHERITANCE");
            Console.WriteLine("---------------------------------------------------");
            TeaWithHook    teaHook    = new TeaWithHook();
            CoffeeWithHook coffeeHook = new CoffeeWithHook();

            Console.WriteLine("\nMaking tea...");
            teaHook.PrepareRecipe();
            Console.WriteLine("\nMaking coffee...");
            coffeeHook.PrepareRecipe();

            Duck[] ducks =
            {
                new Duck("Daffy",   8),
                new Duck("Dewey",   2),
                new Duck("Howard",  7),
                new Duck("Louie",   2),
                new Duck("Donald", 10),
                new Duck("Huey", 2)
            };

            Console.WriteLine("\n\n.NET EXAMPLE (ORDERING ARRAYS)");
            Console.WriteLine("---------------------------------------------------");
            Console.WriteLine("\nBefore sorting:");
            Display(ducks);
            Array.Sort(ducks);
            Console.WriteLine("\nAfter sorting:");
            Display(ducks);
            Console.ReadKey();
        }
示例#2
0
        public void TemplateMethod_CanUseHooks()
        {
            CaffeineBeverageWithHook coffee = new CoffeWithHook();
            CaffeineBeverageWithHook tea    = new TeaWithHook();

            System.Console.WriteLine("Making coffee....");
            coffee.PrepareRecipe();
            System.Console.WriteLine("Making tea.....");
            tea.PrepareRecipe();
        }
示例#3
0
        public static void Run()
        {
            TeaWithHook    teaHook    = new TeaWithHook();
            CoffeeWithHook coffeeHook = new CoffeeWithHook();

            Console.WriteLine("\nMaking tea...");
            teaHook.PrepareRecipe();

            Console.WriteLine("\nMaking coffee...");
            coffeeHook.PrepareRecipe();
        }
        static void Main(string[] args)
        {
            var teaWithHook    = new TeaWithHook();
            var coffeeWithHook = new CoffeeWithHook();

            Console.WriteLine("\nMaking tea...");
            teaWithHook.PrepareRecipe();

            Console.WriteLine("\nMaking coffee...");
            coffeeWithHook.PrepareRecipe();
        }
示例#5
0
        static void Main(string[] args)
        {
            //This first snippet shows the tasks from the template.
            bool wantsCondiments;

            Console.WriteLine("Hello World!");
            CoffeeWithHook coffeHook = new CoffeeWithHook();

            Console.WriteLine("\nMaking coffe...");
            wantsCondiments = coffeHook.customerWantsCondiments();
            coffeHook.prepareRecipe(wantsCondiments);
            //Beverage 2
            TeaWithHook teaHook = new TeaWithHook();

            Console.WriteLine("\nMaking tea...");
            wantsCondiments = teaHook.customerWantsCondiments();
            teaHook.prepareRecipe(wantsCondiments);
            //Beverage 3
            CocoaWithHook cocoaHook = new CocoaWithHook();

            Console.WriteLine("\nMaking tea...");
            wantsCondiments = cocoaHook.customerWantsCondiments();
            cocoaHook.prepareRecipe(wantsCondiments);

            //This second snippet shows the tasks for the bank part.


            // The other part of the client code constructs the actual chain.
            // List<Supervisor> supervisors = new List<Supervisor>
            // ({

            // });
            Console.WriteLine("\nWelcome to Citibank");

            Clerk      clerk      = new Clerk("Clerk 1");
            Supervisor supervisor = new Supervisor("Supervisor 1");
            Manager    manager    = new Manager("Manager 1");

            clerk.SetNext(supervisor);
            supervisor.SetNext(manager);

            // The client should be able to send a request to any handler, not
            // just the first one in the chain.
            Console.WriteLine("Chain: Clerk > Supervisor > Manager\n");
            Console.WriteLine($"Approached {clerk.name}. {clerk.Handle(1000)}");
            Console.WriteLine($"Approached {clerk.name}. {clerk.Handle(2000)}");
            Console.WriteLine($"Approached {clerk.name}. {clerk.Handle(5000)}");
            Console.WriteLine($"Approached {clerk.name}. {clerk.Handle(15000)}");

            // Console.WriteLine("Subchain: Squirrel > Dog\n");
            // Client.ClientCode(squirrel);
        }
 public void Dispose()
 {
     tea                     = null;
     coffee                  = null;
     coffeeWithHook          = null;
     teaWithHook             = null;
     teaResult               = null;
     coffeeResult            = null;
     coffeeWithHookYesResult = null;
     coffeeWithHookNoResult  = null;
     teaWithHookYesResult    = null;
     teaWithHookNoResult     = null;
 }
 public void Init()
 {
     tea                     = new Tea();
     coffee                  = new Coffee();
     coffeeWithHook          = new CoffeeWithHook();
     teaWithHook             = new TeaWithHook();
     teaResult               = new StringBuilder();
     coffeeResult            = new StringBuilder();
     coffeeWithHookYesResult = new StringBuilder();
     coffeeWithHookNoResult  = new StringBuilder();
     teaWithHookYesResult    = new StringBuilder();
     teaWithHookNoResult     = new StringBuilder();
 }
示例#8
0
        static void MakeCoffeeWithHook()
        {
            var teaWithHook = new TeaWithHook();

            Console.WriteLine("Making tea...");
            teaWithHook.PrepareRecipe();

            Console.WriteLine("***************");

            var coffeeWithHook = new CoffeeWithHook();

            Console.WriteLine("Making coffee...");
            coffeeWithHook.PrepareRecipe();
        }
        public void TemplateMethodTest()
        {
            Tea    tea    = new Tea();
            Coffee coffee = new Coffee();

            Console.WriteLine("${Environment.NewLine}Making tea...");
            tea.PrepareRecipe();

            Console.WriteLine($"{Environment.NewLine}Making coffee...");
            coffee.PrepareRecipe();

            TeaWithHook    teaHook    = new TeaWithHook();
            CoffeeWithHook coffeeHook = new CoffeeWithHook();

            Console.WriteLine($"{Environment.NewLine}Making tea...");
            teaHook.PrepareRecipe();

            Console.WriteLine($"{Environment.NewLine}Making coffee...");
            coffeeHook.PrepareRecipe();
        }
示例#10
0
        static void Main(string[] args)
        {
            Console.WriteLine("\n--- Tea ---");
            var tea = new Tea();

            tea.PrepareRecipe();

            Console.WriteLine("\n--- Coffee ---");
            var coffee = new Coffee();

            coffee.PrepareRecipe();

            Console.WriteLine("\n--- Tea (with hook)---");
            var teaWithHook = new TeaWithHook();

            teaWithHook.PrepareRecipe();

            Console.WriteLine("\n--- Coffee (with hook) ---");
            var coffeeWithHook = new CoffeeWithHook();

            coffeeWithHook.PrepareRecipe();
        }
示例#11
0
        static void Main(string[] args)
        {
            #region Strategy
            // Duck mallard = new MallardDuck();
            // mallard.PerformQuack();
            // mallard.PerformFly();

            // Duck model = new ModelDuck();
            // model.PerformFly();
            // model.SetFlyBehavior(new FlyRocketPowered());
            // model.PerformFly();
            #endregion

            #region Observer
            // var weatherData = new WeatherData();

            // var currentDisplay = new CurrentConditions(weatherData);

            // weatherData.SetMeasurements(80, 65, 30.4);
            // weatherData.SetMeasurements(82, 70, 29.2);
            // weatherData.SetMeasurements(78, 90, 29.2);
            #endregion

            #region Decorator
            // var beverage = new Espresso();
            // System.Console.WriteLine($"{beverage.GetDescription()} ${beverage.Cost()}\n");

            // Beverage beverage2 = new DarkRoast();
            // beverage2 = new Mocha(beverage2);
            // beverage2 = new Mocha(beverage2);
            // beverage2 = new Whip(beverage2);
            // System.Console.WriteLine($"{beverage2.GetDescription()} ${beverage2.Cost()}\n");

            // Beverage beverage3 = new HouseBlend();
            // beverage3 = new Soy(beverage3);
            // beverage3 = new Mocha(beverage3);
            // beverage3 = new Whip(beverage3);
            // System.Console.WriteLine($"{beverage3.GetDescription()} ${beverage3.Cost()}\n");
            #endregion

            #region Factory
            // PizzaStore nyPizzaStore = new NYPizzaStore();
            // Pizza pizza = nyPizzaStore.OrderPizza("cheese");

            // System.Console.WriteLine($"Ethan ordered a {pizza.Name}");
            #endregion

            #region Singleton
            // var singleInstance = Singleton.GetInstance();

            // var testNewInstance = Singleton.GetInstance();
            #endregion

            #region Command
            // var remote = new SimpleRemoteControl();

            // var light = new Light();

            // ICommand lightOn = new LightOnCommand(light);

            // remote.SetCommand(lightOn);
            // remote.ButtonWasPressed();

            // var remoteControl = new RemoteControl();

            // var livingRoomLight = new Light("Living Room");
            // var kitchenLight = new Light("Kitchen");

            // var stereo = new Stereo("Living Room");

            // ICommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
            // ICommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            // ICommand kitchenLightOn = new LightOnCommand(kitchenLight);
            // ICommand kitchenLightOff = new LightOffCommand(kitchenLight);

            // remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            // remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);

            // System.Console.WriteLine(remoteControl);

            // remoteControl.OnButtonWasPushed(0);
            // remoteControl.OffButtonWasPushed(0);

            // remoteControl.OnButtonWasPushed(1);
            // remoteControl.OffButtonWasPushed(1);
            #endregion

            #region Adapter and Facade
            // MallardDuck duck = new MallardDuck();

            // WildTurkey turkey = new WildTurkey();
            // Duck turkeyAdapter = new TurkeyAdapter(turkey);

            // System.Console.WriteLine("The Turkey says...");
            // turkey.Gobble();
            // turkey.Fly();
            #endregion

            #region TemplateMethod
            // CaffeineBeverage tea = new Tea();
            // tea.PrepareRecipe();

            // CaffeineBeverage coffe = new Coffe();
            // coffe.PrepareRecipe();

            CaffeineBeverageWithHook coffeeWithHook = new CoffeWithHook();
            coffeeWithHook.PrepareRecipe();

            CaffeineBeverageWithHook teaWithHook = new TeaWithHook();
            teaWithHook.PrepareRecipe();
            #endregion
        }