decorator pattern

When I looked at the problem of synchronizing sessions in redis today, there was a decorator mode involved. By the way, I searched some online. The best one is: https://www.cnblogs.com/mercuryli/p/5284248.html

 

Here is my summary after reading it:

First write an abstract component class that defines the variables and methods that will be used. Equivalent to the largest concept: " drinks "

Then write a variety of  concrete component classes that inherit  the abstract build classes above. Set the value of the original attribute, equivalent to "coffee" (price: ten yuan name: coffee) "milk"  (price: twenty yuan name: milk)

Then write   the decorator abstract class to inherit the abstract construction class and   write  the required abstract methods.

Then write the specific decorator class, introduce the  concrete construction class instance of the abstract component class , inherit the above Decorator abstract class, and implement  the methods of the decorator abstract class ,  

Add setting attributes on the basis of specific component classes (name: " Add  sugar  " + coffee, price: 10+5  )

 


to achieve a combination of drink types and additions.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324988063&siteId=291194637