1. Decoration mode
Dynamically adding some additional responsibilities to an object, the adornment pattern is more flexible than generating subclasses for adding functionality.
* Decoration mode is a way to add more functions to an existing function dynamically.
* Decoration mode separates the core duties of the original class from the decoration function. Simplifies the original class, that is, to remove the repetitive decorative logic of the class.
* Decoration mode puts each decoration function in a separate class and lets the class decorate the object it is decorating.
Namespace design mode {class Program {static void Main (string[] args) {person Andy Lau = new Person (" Andy Lau "); Console.WriteLine ("Start Dress Up"); Tshirt Tshirt = new Tshirt (); Jonson jonson = new Jonson (); Shose shose = new Shose ();
Layers of packaging, constantly adding new decorative tshirt to the original class. Decrator (Andy Lau); Jonson. Decrator (Tshirt); Shose. Decrator (Jonson); Shose. Show (); }}///<summary>///specific needs to be decorated class, also need to enrich the function of the class////</summary> class Person {public Pers On () {} private string name; Public person (string name) {this.name = name; } public virtual void Show () {Console.WriteLine ("Dress up {0}", name); }}///<summary>///Dress class///</summary> class Finery:person {protected Person compo nent; Methods of DecoratingPublic void Decrator (person component) {this.component = component; public override void Show () {if (component!=null) {component. Show (); }}}///<summary>///Specific costumes///</summary> class Tshirt:finery {public ove rride void Show () {Console.WriteLine ("T-shirt");base. Show ();}} class Jonson:finery {public override void Show () {Console.WriteLine ("Jeans"); Base. Show (); }} class Shose:finery {public override void Show () {Console.WriteLine ("Bull Shoes"); Base. Show (); } }}
* Each functional layer is loaded together, then the inner function is called by the topmost instance and the functional layer is expanded according to the base class base method.
(C #) Decorative patterns of design patterns