Decoration pattern of Java design pattern learning

Decoration mode: dynamically add some additional responsibilities to an object. In terms of adding functions, decoration mode is more flexible than generating subclasses.

Advantages: the decorated class and the decorated class can develop independently and will not be coupled with each other. The decoration mode is an alternative mode of inheritance. The decoration mode can dynamically expand the functions of an implementation class.

Disadvantages: multi-layer decoration is more complex.

Example: dressing a person

1: Code structure diagram

2: Create a person class (concretecomponent)

3: Clothing category

4: Specific clothing category

5: Test class

6: Console

Big T-shirt, pants and shoes

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>