An explanation of the difference between undo and redo in Oracle

Source: Internet
Author: User
Tags ole

Learning the design pattern has been a while, the first contact design mode, although the example is simple, vivid, but still feel is very abstract. Today also learned the design pattern of decorative mode, that is, the decoration mode to understand the pattern slightly, the most important feature of the decoration mode is to all the required functions in the correct sequence in series to control. What needs to be emphasized here is the "order", which means that the decoration is built on a certain order, and that the order is controlled by man; Unlike the builder pattern, its order is fixed.


* * Concept

Dynamically adding some extra responsibilities to an object, the adornment pattern is more flexible than generating subclasses for added functionality.


* * Structure diagram

component is the definition of an object interface that can dynamically add responsibilities to these objects. Concretecomponent is to define a specific object, or to add some responsibility to the object. Decorator, abstract decoration class, inherited the component, from the outer class to extend the function of component class, but for component, there is no need to know the existence of Decorator. As for the concretrdecorator is the specific decorative objects, play to the component to add responsibility functions.

* * Instance parsing

The following is an example of xiaoming (specific object in the code), for the specific analysis:

Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks;            Namespace Decoration Mode _ Ultimate Edition _{class Program {//person class "person" ()            {} private string name;            Public person (string name) {this.name = name;            } public virtual void Show () {Console.WriteLine ("Dress up {0}", name);                        }}//Costume class Finery:person {protected person component;            public void decorate (person component) {this.component = component;                    public override void Show () {if (component! = null) {                Component.show ();          }}}//Specific costume class Tshirts:finery {public override void Show ()  {Console.Write ("Big T-shirt");            Base.show (); }} class Bigtrous:finery {public override void Show () {Cons Ole.                Write ("Baggy Pants");            Base.show (); }} class Sneakers:finery {public override void Show () {Cons Ole.                Write ("Broken Sneakers");            Base.show (); }} class Suit:finery {public override void Show () {CONSOLE.W                Rite ("Suit");                Base.show (); }} class Tie:finery {public override void Show () {CONSOLE.WR            ITE ("Tie");            Base.show ();                }} class Leathershoes:finery {public override void Show () {                Console.Write ("Leather Shoes");            Base.show ();       }                } static void Main (string[] args) {Person xc = new Person ("xiaoming");            Console.WriteLine ("\ n First dress up:");            Sneakers pqx = new Sneakers ();            bigtrous KK = new bigtrous ();            Tshirts DTX = new Tshirts (); Pqx.            Decorate (XC); Kk.                                Decorate (PQX); The decoration process is DTX.            Decorate (KK);            Dtx.show ();            Console.WriteLine ("\ n the second dress up:");            leathershoes px = new leathershoes ();            Tie ld = new Tie ();            Suit XZ = new Suit (); Px.            Decorate (XC); Ld.                                Decorate (px); The decorating process XZ.            Decorate (LD);            Xz.show ();        Console.read (); }    }}

In this example, there is no abstract component class, which merges its and concretecomponent classes into "human" classes, with the following structure:



The specific results of the operation are:


Here's why this happens, why it is such a "dress up", and why this is the order, the next step is to give you a detailed introduction (in the first dress as an example):

Sneakers instantiates pqx, Bigtrouser instantiates kk,tshirts instantiation DTX. Then PQX Packaging XC (that is, xiaoming in this example), KK Packaging PQX,DTX Packaging KK, the last to perform DTX. Show (), followed by the instantiation of the reverse order to implement the XC packaging, that is, the results shown above.


* * Advantages

① the decoration function of the class from the class to remove, so as to simplify the original class;

② effectively distinguishes the core functions of the class from the decorative functions, and can remove the repetitive fly decoration logic in the related classes.


* * Regret

Although the decorative mode has a little understanding, but for the decoration process part still have a lot of do not understand, I hope you have a lot of advice, I thanked here.















Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.