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(); }
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() { Component component = new ConcreteComponent(); Decorator decoratorA = new ConcreteDecoratorA(); Decorator decoratorB = new ConcreteDecoratorB(); decoratorA.Component = component; decoratorB.Component = decoratorA; decoratorB.Operation(); }
private static void Main() { var component = new ConcreteComponent(); var concreteDecoratorA = new ConcreteDecoratorA(); var concreteDecoratorB = new ConcreteDecoratorB(); concreteDecoratorA.SetComponent(component); concreteDecoratorB.SetComponent(concreteDecoratorA); concreteDecoratorB.Operation(); Console.ReadKey(); }
private static void NewMethod2() { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); Console.Read(); }
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 c = new ConcreteComponent(); ConcreteDecoratorA dA = new ConcreteDecoratorA(); ConcreteDecoratorB dB = new ConcreteDecoratorB(); dA.SetComponent(c); dB.SetComponent(dA); dB.Operation(); Console.Read(); }
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(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(); // Wait for user Console.ReadKey(); }
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(); }
/// <summary> /// The test first decorator. /// </summary> private static void TestFirstDecorator() { // 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.ReadKey(); }
{ /// <summary> /// Entry point into console application. /// </summary> static void Main() { // 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.ReadKey(); }
/// <summary> /// Entry point into console application. /// </summary> 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.ReadKey(); }
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() { 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(); 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) { Console.WriteLine("Hello World!"); // Decorator ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // 先用ConcreteComponent实例化对象c // 然后用ConcreteComponentA的实例化对象d1包装c d1.SetComponent(c); // 再用ConcreteComponentB的实例化对象d2包装d1 d2.SetComponent(d1); //最终执行d2的Operation() d2.Operation(); Console.Read(); }
static void Main(string[] args) { // Se crea ConcreteComponent y 2 Decoradores ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Se liga los decoradores d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); // Espera al usuario Console.ReadKey(); }
public static void Run() { Console.WriteLine("This structural code demonstrates the Decorator pattern which dynamically adds extra functionality to an existing object."); ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); /* * ConcreteComponent.Operation() * ConcreteDecoratorA.Operation() * ConcreteDecoratorB.Operation() */ }
static void Main() { /* * Structural */ // Create ConcreteComponent and two Decorators StructuralConcreteComponent c = new StructuralConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link Decorators d1.SetComponent(c); d2.SetComponent(d1); // Call decorators operation d2.Operation(); /* * Real World */ // Create a book Book book = new Book("Cantu, Jeremy", "My Life as a Person", 12345); book.Display(); // Create a video Video video = new Video("Tarantino, Quentin", "Jeremy's Life", 54321, 60); video.Display(); // Make video borrow-able, then borrow and display Console.WriteLine("Making video borrow-able"); Borrowable borrowableVideo = new Borrowable(video); borrowableVideo.BorrowItem("Customer #1"); borrowableVideo.BorrowItem("Customer #2"); borrowableVideo.Display(); }
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(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(string[] args) { #region 基本用法(对应Basic.cs) ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); #endregion #region 具体实例(对应Example.cs) Person xc = new Person("小菜"); Console.WriteLine("\n第一种装扮:"); Sneaker pqx = new Sneaker(); BigTrouser kk = new BigTrouser(); TShirt dtx = new TShirt(); pqx.Decorate(xc); kk.Decorate(pqx); dtx.Decorate(kk); dtx.Show(); Console.WriteLine("\n第二种装扮:"); LeatherShoes px = new LeatherShoes(); Tie ld = new Tie(); Suit xz = new Suit(); px.Decorate(xc); ld.Decorate(px); xz.Decorate(ld); xz.Show(); Console.ReadLine(); #endregion }
static void Main(string[] args) { #region 基本用法(对应Basic.cs) ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); #endregion #region 具体实例(对应Example.cs) Person xc = new Person("小菜"); Console.WriteLine("\n第一种装扮:"); Sneaker pqx = new Sneaker(); BigTrouser kk = new BigTrouser(); TShirt dtx = new TShirt(); pqx.Decorate(xc); kk.Decorate(pqx); dtx.Decorate(kk); dtx.Show(); Console.WriteLine("\n第二种装扮:"); LeatherShoes px = new LeatherShoes(); Tie ld = new Tie(); Suit xz = new Suit(); px.Decorate(xc); ld.Decorate(px); xz.Decorate(ld); xz.Show(); Console.ReadLine(); #endregion }
static void Main(string[] args) { #region 结构实现 // 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(); #endregion Console.WriteLine("******************************"); #region 实践应用 #endregion Console.ReadKey(); }
static void Main(string[] args) { var c = new ConcreteComponent(); var d1 = new ConcreteDecoratorA(); var d2 = new ConcreteDecoratorB(); d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); //範例 Person xc = new Person("小菜"); Console.WriteLine("第一種裝扮"); var kk = new BigTrouser(); var dtx = new TShirts(); kk.Decorate(xc); dtx.Decorate(kk); dtx.Show(); Console.ReadLine(); }
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(); }
static void Main(string[] args) { Person person = new Person("小菜"); Console.WriteLine("第一種裝扮:"); Finery tShirts = new TShirts(); Finery bigTrouser = new BigTrouser(); Finery sneakers = new Sneakers(); sneakers.Decorate(person); bigTrouser.Decorate(sneakers); tShirts.Decorate(bigTrouser); tShirts.Show(); Console.WriteLine("\n第二種裝扮:"); Finery suit = new Suit(); Finery tie = new Tie(); Finery leatherShoes = new LeatherShoes(); suit.Decorate(person); tie.Decorate(suit); leatherShoes.Decorate(tie); leatherShoes.Show(); Console.WriteLine("\n"); Component component = new ConcreteComponent(); Decorator decoratorA = new ConcreteDecoratorA(); Decorator decoratorB = new ConcreteDecoratorB(); decoratorA.SetComponent(component); decoratorB.SetComponent(decoratorA); decoratorB.Operation(); Console.ReadLine(); }