static void Main(string[] args) { var ram = new SimpleProduct("Memoria RAM GigaBit Módulo de 16GB", 150000); var processor = new SimpleProduct("Intel Core i7", 750000); var videoCard = new SimpleProduct("nVidia GTX 1050", 1500000); var keyBoard = new SimpleProduct("Keyboard generic 101 keys - Intel", 20000); var mouse = new SimpleProduct("Mouse generic 3 buttons - Intel", 20000); var computerGeneric = new CompositeProduct("Computer Gamer Generic"); computerGeneric.Add(ram); computerGeneric.Add(processor); computerGeneric.Add(videoCard); computerGeneric.Add(keyBoard); computerGeneric.Add(mouse); Console.WriteLine($"Precio de {ram.Name} es: ${ram.GetPrice().ToString("N2")}"); Console.WriteLine($"Precio de {computerGeneric.Name} es: ${computerGeneric.GetPrice().ToString("N2")}"); Console.ReadLine(); }
internal static void Composite() { Console.WriteLine("Composite Pattern Demo"); Console.WriteLine("----------------------------"); Composite.Product ram = new Composite.SimpleProduct("RAM 16 gb", 1000); Composite.Product processor = new Composite.SimpleProduct("Intel Core i7", 2000); Composite.Product videoCard = new Composite.SimpleProduct("nVideo gtx 1050", 500); Composite.Product keyboard = new Composite.SimpleProduct("Perfo X keyb", 1000); Composite.Product mouse = new Composite.SimpleProduct("Dell x", 100); Composite.Product rig = new Composite.SimpleProduct("Tower hp", 2500); Composite.Product led = new Composite.SimpleProduct("Led lg", 4000); Composite.Product gamingKit = new CompositeProduct("Basic Gamer Computer"); gamingKit.Add(ram); gamingKit.Add(processor); gamingKit.Add(videoCard); gamingKit.Add(keyboard); gamingKit.Add(mouse); gamingKit.Add(rig); gamingKit.Add(led); Console.WriteLine(gamingKit.GetPrice()); }