/// <summary> /// going through all the children using recursion to get the final price /// </summary> /// <returns></returns> public static int CalculateTotalPriceRecursion(GiftBase gift) // help { int total = gift.Price; //if(gift.GetChilds() != null) // only if the gift has childes(composite) get inside if (gift.GetChildes() != null) { Console.WriteLine($"{gift.Name} with the price {gift.Price} contains the following products with prices: "); // for every child in our composite start this func again foreach (GiftBase oneGift in gift.GetChildes()) { total += CalculateTotalPriceRecursion(oneGift); } } // if the gift is a leaf else { Console.WriteLine($"{gift.Name} with the price {gift.Price}"); } return(total); }
public void Remove(GiftBase gift) { gifts.Remove(gift); }
public void Add(GiftBase gift) { gifts.Add(gift); }