static void Main(string[] args) { Car theCar = new CompactCar(); theCar = new Sunroof(theCar); Console.WriteLine(theCar.GetDescription()); Console.WriteLine(theCar.GetPrice()); }
static void Main(string[] args) { Car c = new CompactCar(); c = new LeatherDecorator(c); c = new SunRoof(c); System.Console.WriteLine(c.Description); System.Console.WriteLine(c.Price); }
static void Main(string[] args) { Car theCar = new CompactCar(); theCar = new LeatherSeats(theCar); Console.WriteLine(theCar.GetDescription()); Console.WriteLine($"${theCar.GetCarPrice()}"); Console.ReadKey(); }
public static void Main(string[] args) { Car theCar = new CompactCar(); theCar = new Navigation(theCar); theCar = new Sunroof(theCar); theCar = new LeatherSeats(theCar); Console.WriteLine(theCar.GetDescription()); Console.WriteLine($"{theCar.GetCarPrice():C2}"); }
public static void Main() { Car compactCar = new CompactCar(); compactCar = new Navigation(compactCar); compactCar = new Sunroof(compactCar); compactCar = new LeatherSeats(compactCar); Console.WriteLine(compactCar.GetDescription()); Console.WriteLine($"{compactCar.GetCarPrice():C2}"); }
static void Main(string[] args) { Car compactCar = new CompactCar(); compactCar = new Navigation(compactCar); compactCar = new Sunroof(compactCar); Console.WriteLine(compactCar.GetDescription()); Console.WriteLine(compactCar.GetPrice()); Console.ReadLine(); }
static void Main(string[] args) { Car theCar = new CompactCar(); //10,000 theCar = new Navigation(theCar); //5,000 theCar = new Sunroof(theCar); //2,500 theCar = new LeatherSeats(theCar); //2,500 //if you comment out each of Nav/Sun/Leather, //you'll see the total price change accordingly. //each new decorator/wrapper will add to what was already there. //ie, the price, plus whatever the extra cost is. Console.WriteLine(theCar.GetDescription()); Console.WriteLine($"{theCar.GetCarPrice():C2}"); //20,000 Console.ReadKey(); }
internal void Test() { Console.WriteLine($"\nExecution of {GetType().Name} \n"); var compactCar = new CompactCar(); var decorators = new List <ICarDecorator> { new NavigationDecorator(), new SunroofDecorator(), new LeatherSeatsDecorator() }; decorators.ForEach(d => d.Decorate(compactCar)); Console.WriteLine(compactCar.Description); Console.WriteLine($"{compactCar.Price.ToString("C2")}"); }
internal void Test() { Console.WriteLine($"\nExecution of {GetType().Name} \n"); ICar compactCar = new CompactCar(); compactCar = new NavigationDecorator(compactCar); compactCar = new SunroofDecorator(compactCar); compactCar = new LeatherSeatsDecorator(compactCar); Console.WriteLine(compactCar.Description); Console.WriteLine($"{compactCar.Price.ToString("C2")}"); // -------------------- OR -------------------- //var compactCar2 = new LeatherSeatsDecorator(new SunroofDecorator(new NavigationDecorator(new CompactCar()))); //Console.WriteLine(compactCar2.Description); //Console.WriteLine($"{compactCar.Price.ToString("C2")}"); }
static void Main() { Car compactCar = new CompactCar(); Console.WriteLine($"Description: {compactCar.GetDescription()}"); Console.WriteLine($"Description: {compactCar.GetCarPrice()}"); Console.WriteLine(); Car fullSizeCar = new FullSizeCar(); Console.WriteLine($"Description: {fullSizeCar.GetDescription()}"); Console.WriteLine($"Description: {fullSizeCar.GetCarPrice()}"); Console.WriteLine(); Car otherCompactCarWithDecorators = new CompactCar(); otherCompactCarWithDecorators = new LeatherSeatDecorator(otherCompactCarWithDecorators); otherCompactCarWithDecorators = new NavigationDecorator(otherCompactCarWithDecorators); Console.WriteLine($"Description: {otherCompactCarWithDecorators.GetDescription()}"); Console.WriteLine($"Description: {otherCompactCarWithDecorators.GetCarPrice()}"); Console.Read(); }