private static void DecoratorPatternExample() { var concreteComponent = new ConcreteComponent(); var concreteDecorator = new ConcreteDecorator(concreteComponent); concreteDecorator.Operation(); }
public void DecoratorPatternTest() { var concrete = new ConcreteComponent(); var decorator = new ConcreteDecorator(concrete); concrete.Should().Be(decorator.Component); }
public void WhenUserIsNtLoginingIn() { var simple = new ConcreteComponent(); DecoratorWithDisplayChecking decorator = new DecoratorWithDisplayChecking(simple); GetPages <SportPage>().ClientSignInExitClick(decorator); }
private static void ShowDecorator() { Console.WriteLine("================================================"); Console.WriteLine("Pattern code (Decorator):"); ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); Console.WriteLine("\nReal code (Decorator):"); Pizza pizza1 = new ItalianPizza(); pizza1 = new TomatoPizza(pizza1); // итальянская пицца с томатами Console.WriteLine("Название: {0}", pizza1.Name); Console.WriteLine("Цена: {0}", pizza1.GetCost()); Pizza pizza2 = new ItalianPizza(); pizza2 = new CheesePizza(pizza2);// итальянская пиццы с сыром Console.WriteLine("Название: {0}", pizza2.Name); Console.WriteLine("Цена: {0}", pizza2.GetCost()); Pizza pizza3 = new BulgerianPizza(); pizza3 = new TomatoPizza(pizza3); pizza3 = new CheesePizza(pizza3);// болгарская пиццы с томатами и сыром Console.WriteLine("Название: {0}", pizza3.Name); Console.WriteLine("Цена: {0}", pizza3.GetCost()); }
static void DecoratorTester() { #region sample 1 var c = new ConcreteComponent(); var d1 = new ConcreteDecoratorA(); var d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); #endregion #region sample 2 var book = new Book("Worley", "Inside ASP.NET", 10); book.Display(); // Create video var video = new Video("Spielberg", "Jaws", 23, 92); video.Display(); // Make video borrowable, then borrow and display Console.WriteLine("\nMaking video borrowable:"); var borrowvideo = new Borrowable(video); borrowvideo.BorrowItem("Customer #1"); borrowvideo.BorrowItem("Customer #2"); borrowvideo.Display(); #endregion }
static bool TestDecoratorPattern() { Console.WriteLine("TESTING THE DECORATOR DESIGN PATTERN: "); ConcreteComponent comp = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(comp); ConcreteDecoratorB d2 = new ConcreteDecoratorB(d1); comp.Operation(); //Output: //Operation from ConcreteComponent d1.Operation(); //Output: //Operation from ConcreteComponent //(AddedBehaviour A) + Operation from ConcreteDecoratorA d2.Operation(); //Output: //Operation from ConcreteComponent //(AddedBehaviour A) + Operation from ConcreteDecoratorA //(AddedBehaviour B) + Operation from ConcreteDecoratorB return(true); }
public void Create_Pizza() { var oven = new ConcreteComponent(); var product = oven.Cook(); Assert.AreEqual("Pizza", product); }
public void TestCase1() { var component1 = new ConcreteComponent(); var component2 = new ConcreteDecorator(component1); component2.Operation(); }
static void Main() { IComponent component = new ConcreteComponent(); IComponent decorator = new Decorator(component); var p = new Decorator(decorator); p.Do(); }
public static void Test() { var concreteComponent = new ConcreteComponent("concrete property", "component property"); concreteComponent.Operation(); var concreteDecorator = new ConcreteDecorator(concreteComponent); concreteDecorator.AnotherOperation(); }
public static void Run() { var component = new ConcreteComponent(); var decoratorA = new ConcreteDecorator(component); var decoratorB = new ConcreteDecorator(decoratorA); decoratorB.Execute(); }
static void Main() { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(c); ConcreteDecoratorB d2 = new ConcreteDecoratorB(d1); d2.Operation(); Console.ReadKey(); }
public void AddBehaviorTest() { Component component = new ConcreteComponent(); component = new ConcreteDecoratorB(component); Assert.That(() => component.Operation(), Throws.Exception.With.Message.EqualTo("Operation from object of ConcreteDecoratorB type")); }
private static void DecoratorModeTest() { Component component, component1, component2; component = new ConcreteComponent(); component1 = new ConcreteDecorator(component); //二次装饰 component2 = new ConcreteDecorator2(component1); component2.Operation(); }
static void Main() { Component component = new ConcreteComponent(); Decorator decoratorA = new ConcreteDecoratorA(); Decorator decoratorB = new ConcreteDecoratorB(); decoratorA.Component = component; decoratorB.Component = decoratorA; decoratorB.Operation(); }
public void AddStateTest() { Component component = new ConcreteComponent(); component = new ConcreteDecoratorA(component); Assert.That((component as ConcreteDecoratorA)?.AddedState == "added state"); Assert.That(() => component.Operation(), Throws.Exception.With.Message.EqualTo("Operation from object of ConcreteComponent type")); }
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 UseCase() { AbstractComponent component = new ConcreteComponent(); AbstractDecorator decorator1 = new ConcreteDecoratorOne(); AbstractDecorator decorator2 = new ConcreteDecoratorTwo(); decorator1.Component = component; decorator2.Component = decorator1; decorator2.Operation(); }
public void DecoratorUsage() { ConcreteComponent c = new ConcreteComponent(); ConcreteDecorator d1 = new ConcreteDecorator(c); ConcreteDecorator d2 = new ConcreteDecorator(d1); d2.Operation(); Assert.IsTrue(true); }
public void TestMethod1() { var component = new ConcreteComponent(); var decoratorA = new ConcreateDecoratorA(); var decoratorB = new ConcreateDecoratorB(); decoratorA.SetComponent(component); decoratorB.SetComponent(decoratorA); decoratorB.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 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()); }
static void Main(string[] args) { // Decorators Component simple = new ConcreteComponent(); DecoratorAlpha decoratorAlpha = new DecoratorAlpha(simple); DecoratorBeta decoratorBeta = new DecoratorBeta(decoratorAlpha); Console.WriteLine(simple.Operation()); Console.WriteLine(decoratorAlpha.Operation()); Console.Write(decoratorBeta.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(); }
public void DecoratorTest() { { var m = new ConcreteComponent(); var decoratorA = new DecoratorA(m); // decoratorA.Work(); var decoratorB = new DecoratorB(decoratorA); decoratorB.Work(); } { // 我买了个苹果手机 Phone phone = new ApplePhone(); // 现在想贴膜了 var applePhoneWithSticker = new Sticker(phone); // 扩展贴膜行为 applePhoneWithSticker.Print(); // 现在我想有挂件了 var applePhoneWithAccessories = new Accessories(phone); // 扩展手机挂件行为 applePhoneWithAccessories.Print(); Console.WriteLine("----------------------"); // 现在我同时有贴膜和手机挂件了 var sticker = new Sticker(phone); var applePhoneWithAccessoriesAndSticker = new Accessories(sticker); applePhoneWithAccessoriesAndSticker.Print(); } // { // AbstractMessage message = new SqlMessage(); // var de = new CheckUserWrapper(message); // Console.WriteLine(de.Get()[0].Message); // // var d2 = new CheckInputWrapper(message); // Console.WriteLine(d2.Get()[0].Message); // // var m3 = new CheckUserWrapper(message); // var m4 = new CheckInputWrapper(m3); // Console.WriteLine(m4.Get()[0].Message); // } { var dark = new DarkRoast("黑咖啡"); var sugar = new Sugar("加糖", dark); Console.WriteLine($"{sugar.GetDescription()}{sugar.Cost()}元");; var milk = new Milk("加奶", sugar); Console.WriteLine($"{milk.GetDescription()}{milk.Cost()}元");; } }
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() { // 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(); }
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 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 void DecoratorTest() { var simple = new ConcreteComponent(); Client.ClientCode(simple).Should().Be(StructuralText.ConcreteComponent); // Note how decorators can wrap not only simple components but the other decorators as well. var decorator1 = new ConcreteDecoratorA(simple); var decorator2 = new ConcreteDecoratorB(decorator1); Client.ClientCode(decorator2).Should().Be(StructuralText.ConcreteDecoratorB + StructuralText.ConcreteDecoratorA + StructuralText.ConcreteComponent); }
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(); }
// void UnitTest () { // 物件 ConcreteComponent theComponent = new ConcreteComponent(); // 增加Decorator ConcreteDecoratorA theDecoratorA = new ConcreteDecoratorA( theComponent ); theDecoratorA.Operator(); ConcreteDecoratorB theDecoratorB = new ConcreteDecoratorB( theComponent ); theDecoratorB.Operator(); // 再增加一層 ConcreteDecoratorB theDecoratorB2 = new ConcreteDecoratorB( theDecoratorA ); theDecoratorB2.Operator(); }
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(); }