Decorator mode enables you to wrap objects one layer at a level by using inheritance.
1,person is a decorated object, in the decorator pattern class diagram, all classes inherit from the person class. The person class has a show method that shows which costumes for the person object are decorated. By inheritance, all classes have a show method, so when a person wears some kind of costume, it is possible to invoke the Show method of the costume. When there are no costumes to decorate the person, the execution of the Show method represents the most original.
2, the abstract costume class inherits from the person class, although from the natural concept, the dress is not human. However, inheritance is still used here. One reason is that this kind of abstract clothing class has a show method, so that the specific clothing class also has a show method, when using a specific dress to decorate the object, you can use the Show method of the costume show.
3, although the abstract costume class inherits the person class, it also has a property of the person class, which is used to specify which object to decorate for each specific costume class. Because this property is person type, so class A dress can decorate class B dress, B dress can decorate C class dress, ... The final class N costumes have the person object (in turn).
4, since each specific costume inherits the show method from the parent class, in the Show method, each specific costume has a personal decoration, and then calls the parent's decorations (the so-called layer-by-layer wrapper).
The decorator mode of the big talk design pattern