PHP Decorator pattern of design pattern （Decorator）
The decorator pattern allows us to add new functionality to a class , Without changing its original structure . This type of class belongs to the structural class , It is a wrapper for existing classes
Application scenario of decorator mode
When we're going to draw a circle , Let's create a circular class , Square creates another class , The ellipse 、 Rectangle ...., And when we're going to color these graphics , If we use the inheritance method , Then the class files in our project will grow exponentially . If we use decorators at this time , We can skillfully use aggregation instead of inheritance to solve the problem of so many kinds of files . And it makes the code more flexible , Better code reuse .