public void builder_test_beverage()
        {
            BeverageRecipe   recipe;
            BeverageDirector director = new BeverageDirector();

            #region Tea
            {
                TeaBeverageBuilder builder = new TeaBeverageBuilder();
                recipe = director.MakeBeverageRecipe(builder);

                Assert.That(recipe.BeverageType == Beverage.Tea);
                Assert.That(recipe.Water == 40);
                Assert.That(recipe.Milk == 50);
                Assert.That(recipe.Sugar == 10);
                Assert.That(recipe.PowderQuantity == 15);
            }
            #endregion

            #region Coffee
            {
                CoffeeBeverageBuilder builder = new CoffeeBeverageBuilder();
                recipe = director.MakeBeverageRecipe(builder);

                Assert.That(recipe.BeverageType == Beverage.Coffee);
                Assert.That(recipe.Water == 50);
                Assert.That(recipe.Milk == 60);
                Assert.That(recipe.Sugar == 15);
                Assert.That(recipe.PowderQuantity == 20);
            }
            #endregion
        }
예제 #2
0
        private static void Main(string[] args)
        {
            //AbstractFactory
            //Provide an interface for creating related objects without specifying their concrete classes.

            AfricaFactory africa = new AfricaFactory();
            AnimalWorld   world  = new AnimalWorld(africa);

            world.RunFoodChain();

            AmericaFactory america = new AmericaFactory();

            world = new AnimalWorld(america);
            world.RunFoodChain();

            Console.WriteLine("\n");

            //=============================================================================================================================================================

            //Singleton
            //Ensure a class has only one instance and provide a global point of access to it.

            Singleton fromPrincipal = Singleton.GetInstance;

            fromPrincipal.PrintDetails("From Principal");
            Singleton fromTeachaer = Singleton.GetInstance;

            fromTeachaer.PrintDetails("From Teacher");
            Singleton fromStudent = Singleton.GetInstance;

            fromStudent.PrintDetails("From Student");

            Singleton oSingleton_1 = new Singleton();
            Singleton oSingleton_2 = new Singleton();

            Console.WriteLine("\n");

            //=============================================================================================================================================================

            //ProtoType
            //The intent behind the usage of a Prototype pattern is for creation of an object clone;
            //in other words it allows us to create a new instance by copying existing instances.

            var dev = new Developer
            {
                FirstName = "Gary",
                Lastname  = "Woodfine",
                Skills    = new List <string> {
                    "C#", "PHP", "SQL", "JavaScript"
                }
            };

            var dev2 = dev.Clone() as Developer;

            Console.WriteLine($"The Cloned  Developer name is { dev2.FirstName }  { dev2.Lastname }");

            Console.WriteLine("The second developer has the following skills: ");

            foreach (var skill in dev2.Skills)
            {
                Console.WriteLine(skill);
            }

            Console.WriteLine("\n");

            //=============================================================================================================================================================

            // Facade
            //Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.

            Order order = new Order();

            order.PlaceOrder();

            Console.WriteLine("\n");

            //==============================================================================================================================================================

            // Builder
            //Builder is a creational design pattern that lets you construct complex objects step by step.

            Beverage         beverage;
            BeverageDirector beverageDirector = new BeverageDirector();

            TeaBuider tea = new TeaBuider();

            beverage = beverageDirector.MakeBeverage(tea);
            Console.WriteLine(beverage.ShowBeverage());

            CoffeeBuilder coffee = new CoffeeBuilder();

            beverage = beverageDirector.MakeBeverage(coffee);
            Console.WriteLine(beverage.ShowBeverage());
            Console.Read();
        }
예제 #3
0
        static void Main(string[] args)
        {
            #region Sample1

            /* MealBuilder mealBuilder = new MealBuilder();
             *
             * Meal vegMeal = mealBuilder.PrepareVegMeal();
             * Console.WriteLine("Veg Meal");
             * vegMeal.showItems();
             * Console.WriteLine("Total Cost: " + vegMeal.GetCost());
             *
             * Meal nonVegMeal = mealBuilder.PrepareNonVegMeal();
             * Console.WriteLine("\nNon-Veg Meal");
             * nonVegMeal.showItems();
             * Console.WriteLine("Total Cost: " + nonVegMeal.GetCost()); */
            #endregion

            #region Sample2

            /*Waiter waiter = new Waiter();
             * PizzaBuilder hawaiianPizzabuilder = new HawaiianPizzaBuilder();
             * waiter.SetPizzaBuilder(hawaiianPizzabuilder);
             * waiter.ConstructPizza();
             *
             * PizzaBuilder spicyPizzaBuilder = new SpicyPizzaBuilder();
             * waiter.SetPizzaBuilder(spicyPizzaBuilder);
             * waiter.ConstructPizza();
             *
             * Pizza pizza = waiter.GetPizza(); */
            #endregion

            #region Sample3

            /* VehicleBuilder builder;
            *
            *  // Create shop with vehicle builders
            *  Shop shop = new Shop();
            *
            *  // Construct and display vehicles
            *  builder = new ScooterBuilder();
            *  shop.Construct(builder);
            *  builder.Vehicle.Show();
            *  builder = new CarBuilder();
            *  shop.Construct(builder);
            *
            *  builder.Vehicle.Show();
            *  builder = new MotorCycleBuilder();
            *
            *  shop.Construct(builder);
            *  builder.Vehicle.Show(); */
            #endregion

            #region Sample4

            /* Console.WriteLine("***Builder Pattern Demo***");
             * Director director = new Director();
             *
             * IBuilder b1 = new Car("Ford");
             * IBuilder b2 = new MotorCycle("Honda");
             *
             * // Making Car
             * director.Construct(b1);
             * Product p1 = b1.GetVehicle();
             * p1.Show();
             *
             * //Making MotorCycle
             * director.Construct(b2);
             * Product p2 = b2.GetVehicle();
             * p2.Show(); */
            #endregion

            #region Sample5

            /* Report report;
             * ReportDirector reportDirector = new ReportDirector();
             * // Construct and display Reports
             * report = reportDirector.MakeReport(new PDFReport());
             * report.DisplayReport();
             * Console.WriteLine("-------------------");
             *
             * report = reportDirector.MakeReport(new ExcelReport());
             * report.DisplayReport(); */
            #endregion

            #region Sample6

            /* var director = new DirectorNew();
             *
             * var builder = new CarNewBuilder();
             * director.ConstructSportsCar(builder);
             * var car = builder.GetProduct();
             * car.GetResult();
             *
             * System.Console.WriteLine("*********************************");
             *
             * var manualBuilder = new CarManualBuilder();
             * director.ConstructCityCar(manualBuilder);
             * var manual = manualBuilder.GetProduct();
             * manual.GetResult();
             * System.Console.WriteLine("-------------------------------");
             * System.Console.WriteLine(manual.Print()); */
            #endregion

            #region Sample7

            /* var localGameBuilder = new LocalGameBuilder()
             *                      .AiStrength(20)
             *                      .BoardSize(10)
             *                      .Level(2)
             *                      .Present()
             *                      .Build();
             *
             * var onlineGameBuilder = new OnlineGameBuilder()
             *                      .ServerUrl("http://myGame.ca/")
             *                      .BoardSize(20)
             *                      .Level(5)
             *                      .Present()
             *                      .Build(); */
            #endregion

            #region Sample8

            /* var builder = new ProductStockReportBuilder(
             * new System.Collections.Generic.List<ProductNew> {
             *      new ProductNew { Name = "Monitor", Price = 200.50 },
             *      new ProductNew { Name = "Mouse", Price = 20.41 },
             *      new ProductNew { Name = "Keyboard", Price = 30.15}
             *  });
             * var ProductStockReportDirector = new ProductStockReportDirector(builder);
             *
             * ProductStockReportDirector.BuildStockReport();
             * var report = builder.GetReport();
             *
             * Console.WriteLine(report); */
            #endregion

            #region Sample9

            /* Window window = new WindowBuilder()
             *  .Width(800)
             *  .Height(400)
             *  .Build();
             *
             * Console.WriteLine();
             * Console.WriteLine("-----------");
             *
             * Dialog dialog = new DialogBuilder()
             *  .Width(500)
             *  .Message("Hello")
             *  .Height(400)
             *  .Build(); */
            #endregion

            #region Sample10

            /* OrderBuilder builder = new OrderBuilder();
             *
             * OrderedItems orderedItems = builder.PreparePizza();
             *
             * orderedItems.ShowItems();
             *
             * Console.WriteLine("\n");
             * Console.WriteLine("Total Cost : " + orderedItems.GetCost()); */
            #endregion

            #region Sample11

            /* CDBuilder cdBuilder = new CDBuilder();
             * CDType cdType1 = cdBuilder.BuildSonyCD();
             * cdType1.ShowItems();
             *
             * CDType cdType2 = cdBuilder.BuildSamsungCD();
             * cdType2.ShowItems(); */
            #endregion

            #region Sample12
            var beverageDirector = new BeverageDirector();

            var tea      = new TeaBuider();
            var beverage = beverageDirector.MakeBeverage(tea);

            Console.WriteLine(beverage.ShowBeverage());
            var coffee = new CoffeeBuilder();
            beverage = beverageDirector.MakeBeverage(coffee);
            Console.WriteLine(beverage.ShowBeverage());
            #endregion

            Console.ReadKey();
        }