static void Main(string[] args) { ShoppingMall shoppingMall = new ShoppingMall(null); shoppingMall.CustomerName = $"{DateTime.Now.DayOfWeek.ToString()} customer"; shoppingMall.BillingAmount = 1000; switch (DateTime.Now.DayOfWeek) { case DayOfWeek.Monday: case DayOfWeek.Tuesday: case DayOfWeek.Wednesday: shoppingMall.CurrentStrategy = new LowDiscountStrategy(); break; case DayOfWeek.Thursday: case DayOfWeek.Friday: shoppingMall.CurrentStrategy = new HighDiscountStrategy(); break; case DayOfWeek.Saturday: case DayOfWeek.Sunday: shoppingMall.CurrentStrategy = new NoDiscountStrategy(); break; default: shoppingMall.CurrentStrategy = new NoDiscountStrategy(); break; } Console.WriteLine($"Final Bill is : {shoppingMall.GetFinalBill()}"); }
static void Main(string[] args) { ShoppingMall shopping = new ShoppingMall(null); shopping.CustomerName = "Arvind D C"; shopping.BillAmount = 1000; switch (DateTime.Now.DayOfWeek) { case DayOfWeek.Monday: shopping.CurrentStrategy = new LowDiscount(); break; case DayOfWeek.Tuesday: shopping.CurrentStrategy = new HighDiscount(); break; default: shopping.CurrentStrategy = new NoDiscountStrategy(); break; } Console.WriteLine("Dear {0}, Total Bill Amount after Discount is {1}", shopping.CustomerName, shopping.GetFinalBill()); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Behaviour type :Strategy pattern example"); Console.WriteLine("-----------------------------------"); Console.WriteLine("What is Strategy pattern : "); // Approch one ShoppingMall objshoppingMall = new ShoppingMall(new LowDiscountStrategy()) { customerName = "Monday Customer", billAmount = 1000 }; Console.WriteLine("Monday final bill -" + objshoppingMall.getFinalBill()); ShoppingMall objshoppingMall1 = new ShoppingMall(new HighDisocuntStrategy()) { customerName = "Friday Customer", billAmount = 1000 }; Console.WriteLine("Friday final bill -" + objshoppingMall1.getFinalBill()); ShoppingMall objshoppingMall2 = new ShoppingMall(new NoDiscountStrategy()) { customerName = "Sunday Customer", billAmount = 1000 }; Console.WriteLine("Sunday final bill -" + objshoppingMall2.getFinalBill()); // Approch Two ShoppingMall objshoppingMallGeneric = new ShoppingMall(null) { customerName = "Monday Customer", billAmount = 1000 }; switch (DateTime.Now.DayOfWeek) { case DayOfWeek.Sunday: objshoppingMallGeneric.currentStrategy = new LowDiscountStrategy(); break; case DayOfWeek.Monday: break; case DayOfWeek.Tuesday: break; case DayOfWeek.Wednesday: break; case DayOfWeek.Thursday: break; case DayOfWeek.Friday: break; case DayOfWeek.Saturday: break; default: break; } Console.ReadLine(); }