コード例 #1
0
        static void Main(string[] args)
        {
            var rootBox  = new CompositeGift("RootBox", 0);
            var truckToy = new SingleGift("TruckToy", 289);
            var plainToy = new SingleGift("PlainToy", 587);

            rootBox.Add(truckToy);
            rootBox.Add(plainToy);
            var childBox   = new CompositeGift("ChildBox", 0);
            var soldierToy = new SingleGift("SoldierToy", 200);

            childBox.Add(soldierToy);
            //rootBox.Add(childBox);
            rootBox.Show();
            Console.WriteLine($"Total price is: {rootBox.CalculateTotalPrice()}");
            IGiftOrder member = new MemberOrder(rootBox.Name, rootBox.Price);

            member = new PremiumOrderDecorator(member);
            System.Console.WriteLine($"Total price is: {member.Discount(rootBox)}\n");

            childBox.Show();
            IGiftOrder regular = new MemberOrder(childBox.Name, childBox.Price);

            regular = new PreOrderDecorator(regular);
            System.Console.WriteLine($"Total price is: {regular.Discount(childBox)}");
        }
コード例 #2
0
 public double Discount(CompositeGift gift)
 {
     System.Console.WriteLine("Calculating the total price as Preorder");
     return(gift.CalculateTotalPrice() * 0.7);
 }
コード例 #3
0
 public override double Discount(CompositeGift gift)
 {
     Console.WriteLine($"Calculating the total price in a MemberOrderDecorator class");
     return(base.Discount(gift) * 0.8);
 }
コード例 #4
0
 public virtual double Discount(CompositeGift gift)
 {
     Console.WriteLine($"Calculating the total price in a decorator class");
     return(order.Discount(gift));
 }
コード例 #5
0
 public override double Discount(CompositeGift gift)
 {
     Console.WriteLine("Calculating the total price after adding Preorder disconut");
     return(base.Discount(gift) * 0.9);
 }