public static void Main(string[] args) { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); }
public static void DecoratorPattern() { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); Console.Read(); }
public static void TestDecorator() { IComponent component = new ConcreteComponent(); Console.WriteLine(component.Operation()); Decorator decorator = new ConcreteDecoratorA(component); Console.WriteLine(decorator.Operation()); decorator = new ConcreteDecoratorB(decorator); Console.WriteLine(decorator.Operation()); }
public static void TestConcreteDecorators() { var c = new ConcreteComponent(); var d1 = new ConcreteDecoratorA(); var d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); StringAssert.AreEqualIgnoringCase(d2.Operation(true), "ConcreteDecoratorB.Operation()ConcreteDecoratorA.Operation()ConcreteComponent.Operation()"); }
public void TestDecorator() { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); }
static void Main(string[] args) { ConcreteComponent component = new ConcreteComponent(); ConcreteDecoratorA da = new ConcreteDecoratorA(); ConcreteDecoratorB db = new ConcreteDecoratorB(); da.SetComponent(component); db.SetComponent(da); db.Operation(); Console.ReadKey(true); }
static void Main(string[] args) { ConcreteComponent TextView = new ConcreteComponent(); ConcreteDecoratorA ScrollDecorator = new ConcreteDecoratorA(); ConcreteDecoratorB BorderDecorator = new ConcreteDecoratorB(); ScrollDecorator.SetComponent(TextView); BorderDecorator.SetComponent(ScrollDecorator); BorderDecorator.Operation(); Console.ReadLine(); }
static void Main() { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); Console.ReadKey(); }
public static void DecoratorStructural() { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); }
static void Main(string[] args) { ConcreteComponent concreteComponent = new ConcreteComponent(); ConcreteDecoratorA concreteDecoratorA = new ConcreteDecoratorA(); ConcreteDecoratorB concreteDecoratorB = new ConcreteDecoratorB(); concreteDecoratorA.Component = concreteComponent; concreteDecoratorB.Component = concreteDecoratorA; concreteDecoratorB.Operation(); Console.Read(); }
static void Main() { { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); } }
private static void Test1() { // 首先实例化具体对象ConcreateComponent 【具体组合】 ConcreateComponent c = new ConcreateComponent(); // 然后实例化具体装饰类 ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // 开始包装 d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); }
static void Main(string[] args) { Component component = new ConcreteComponent(); Abstraction.Decorator decoratorA = new ConcreteDecoratorA(); Abstraction.Decorator decoratorB = new ConcreteDecoratorB(); decoratorA.Component = component; decoratorB.Component = decoratorA; decoratorB.Operation(); Console.ReadKey(); }
private static void Test() { var c = new ConcreteComponent(); var d1 = new ConcreteDecoratorA(); var d2 = new ConcreteDecoratorB(); //Tutaj widac dekoracje d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); Console.ReadKey(); }
public Client() { ConcreteComponent concreteComponent = new ConcreteComponent(); ConcreteDecoratorA concreteDecoratorA = new ConcreteDecoratorA(); ConcreteDecoratorB concreteDecoratorB = new ConcreteDecoratorB(); concreteDecoratorA.SetComponent(concreteComponent); concreteDecoratorB.SetComponent(concreteDecoratorA); concreteDecoratorB.Operation(); Console.Read(); }
public static void Create() { var c = new ConcreteComponent(); var d1 = new ConcreteDecoratorA(); var d2 = new ConcreteDecoratorB(); // Link decorators. d1.Component = c; d2.Component = d1; // Do the operation. d2.Operation(); }
static void Run() { //实例化实现类 ConcreteComponent concrete = new ConcreteComponent(); //实例化装饰类 ConcreteDecoratorA decoratorA = new ConcreteDecoratorA(); ConcreteDecoratorB decoratorB = new ConcreteDecoratorB(); //用装饰类装饰实现类 decoratorA.SetComponent(concrete); decoratorB.SetComponent(decoratorA); // decoratorB.Operation(); }
// "Component" public void TestDecoratorPattern() { // Create ConcreteComponent and two Decorators var c = new ConcreteComponent(); var d1 = new ConcreteDecoratorA(); var d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); // Wait for user Console.Read(); }
//Декоратор або Wrapper / Обгортка (Decorator) public Run Decorator() { Console.WriteLine("\nDecorator:"); // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); return(this); }
static void Main(string[] args) { Component component = new ConcreteComponent(); //第一次修饰 component = new ConcreteDecoratorA(component); //第二次装饰 component = new ConcreteDecoratorB(component); component.Operation(); //Person p = new Person("sun"); //Shirt t = new Shirt(); //t.Decorate(p); //t.Show(); Console.ReadLine(); }
public static void Main() { ConcreteComponent cc = new ConcreteComponent(); cc.Operation(); Console.WriteLine(); ConcreteDecoratorA cd1 = new ConcreteDecoratorA(cc); cd1.Operation(); Console.WriteLine(); ConcreteDecoratorB cd2 = new ConcreteDecoratorB(cd1); cd2.Operation(); Console.WriteLine(); Console.ReadKey(); }
public static void Main( string[] args ) { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent( c ); d2.SetComponent( d1 ); d2.Operation(); }
/// <summary> /// Execute decorator design pattern example /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Decorator_OnClick(object sender, RoutedEventArgs e) { var simpleComponent = new ConcreteComponent(); DesignPatternsLog.Text += $"Decorator@ I get a simple component: {simpleComponent.Operation()}"; DesignPatternsLog.Text += $"{Environment.NewLine}"; // Note how decorators can wrap not only simple components // but the other decorators as well. var decoratorA = new ConcreteDecoratorA(simpleComponent); var decoratorB = new ConcreteDecoratorB(decoratorA); DesignPatternsLog.Text += $"Decorator@ Now I've got a decorated component: {decoratorB.Operation()}"; DesignPatternsLog.Text += $"{Environment.NewLine}"; }
static void Main() { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); // Wait for user Console.Read(); }