//https://ru.wikipedia.org/wiki/Декоратор_(шаблон_проектирования) //https://refactoring.guru/ru/design-patterns/decorator //https://metanit.com/sharp/patterns/4.1.php static void Main(string[] args) { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA dA = new ConcreteDecoratorA(); ConcreteDecoratorB dB = new ConcreteDecoratorB(); // Link decorators dA.SetComponent(c); dB.SetComponent(dA); dA.Operation(); dB.Operation(); //OnInterface Implement implement = new Implement(); ConcreteDecoratorAI dAI = new ConcreteDecoratorAI(); ConcreteDecoratorBI dBI = new ConcreteDecoratorBI(); // Link decorators dAI.SetComponent(implement); dBI.SetComponent(dAI); implement.Operation(); dAI.Operation(); dBI.Operation(); // Wait for user Console.Read(); }
static void Main(string[] args) { Component component = new ConcreteComponent(); DecoratorClass decorator = new ConcreteDecoratorA(); decorator.SetComponent(component); decorator.Operation(); }
static void Main(string[] args) { Component myComponent = new ConcreteComponent(); Console.WriteLine("CC: {0}", myComponent.Operation()); myComponent = new ConcreteDecoratorA(myComponent); Console.WriteLine("CC + DCA: {0}", myComponent.Operation()); myComponent = new ConcreteDecoratorB(myComponent); Console.WriteLine("CC + DCB: {0}", myComponent.Operation()); }
static void Main(string[] args) { var compo = new ConcreteComponent(); var decorator1 = new ConcreteDecoratorA(compo); var decorator2 = new ConcreteDecoratorB(compo); var decorator3 = new ConcreteDecoratorA(new ConcreteDecoratorB(compo)); compo.Operation(); decorator1.Operation(); decorator2.Operation(); decorator3.Operation(); }
static void Main() { ConcreteComponent cmp = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(cmp); d2.SetComponent(cmp); d1.Operation(); d2.Operation(); Console.ReadKey(); }
static void Main(string[] args) { Component component = new ConcreteComponent("Start"); Console.WriteLine(component.Operation()); component = new ConcreteDecoratorA(component); Console.WriteLine(component.Operation()); component = new ConcreteDecoratorB(component); Console.WriteLine(component.Operation()); Console.ReadLine(); }
static void Main() { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA dA = new ConcreteDecoratorA(); ConcreteDecoratorB dB = new ConcreteDecoratorB(); dA.SetComponent(c); dB.SetComponent(dA); dA.Operation(); Console.WriteLine(); dB.Operation(); Console.Read(); }
static void Main(string[] args) { ConcreteComponent concreteComponent = new ConcreteComponent(); concreteComponent.Operation(); ConcreteDecoratorA decoratorA = new ConcreteDecoratorA(); decoratorA.SetComponent(concreteComponent); ConcreteDecoratorB decoratorB = new ConcreteDecoratorB(); decoratorB.SetComponent(concreteComponent); decoratorA.Operation(); decoratorB.Operation(); Console.WriteLine("-----------------------------"); Repo repo = new Repo(); repo.GetId(); DecoratorForIRepo decoratorForIRepo = new DecoratorForIRepo(repo); decoratorForIRepo.GetId(); Console.WriteLine("-----------------------------"); new CofeeHelper().ShouldSupportCondiments(); Console.WriteLine("-----------------------------"); BaseCar baseCar = new BaseCar(); Console.WriteLine(baseCar.GetCarCharacteristic()); Console.WriteLine(baseCar.GetCost()); ICarSet superCar = new AutomaticTransmissionSet(baseCar); Console.WriteLine(superCar.GetCarCharacteristic()); Console.WriteLine(superCar.GetCost()); }
static void Main(string[] args) { ConcreteComponent cc = new ConcreteComponent(); cc.Operation(); Console.WriteLine(); ConcreteDecoratorA cd1 = new ConcreteDecoratorA(cc); cd1.Operation(); Console.WriteLine(); ConcreteDecoratorB cd2 = new ConcreteDecoratorB(cc); cd2.Operation(); Console.WriteLine(); Console.ReadKey(); }
static void Main() { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA dA = new ConcreteDecoratorA(); ConcreteDecoratorB dB = new ConcreteDecoratorB(); // Link decorators dA.SetComponent(c); dB.SetComponent(dA); dA.Operation(); Console.WriteLine(); dB.Operation(); // Wait for user Console.Read(); }
static void Main() { // Конкретный компонент и 3 Конкретных декоратора ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA dA = new ConcreteDecoratorA(); ConcreteDecoratorB dB = new ConcreteDecoratorB(); ConcreteDecoratorB dB2 = new ConcreteDecoratorB(); dA.SetComponent(c); //оборачиваем с в первый декоратор dB.SetComponent(c); dB2.SetComponent(dA); //оборачиваем dA во второй декоратор dA.Operation(); Console.WriteLine(); dB.Operation(); Console.WriteLine(); dB2.Operation(); Console.Read(); }
public static void Main(string[] args) { AbstractComponent abstractComponent = new ConcreteDecoratorA(new ConcreteDecoratorB(new ConcreteComponent())); abstractComponent.Operation(); }