1: Background introduction-clothing for snacks
Practice 1:
Define the person class and call methods in sequence
Disadvantages: it violates the open-closed principle.
Practice 2:
Define the person class and apparel abstract class. The specific class inherits the abstract class.
Disadvantages: too many repeated code calls on the client, and the functions are not separated, so it is not convenient to add new functions.
Client call:
The required functions need to be connected in the correct order for control.
Practice 3 (Decoration Mode):
Adding some additional responsibilities to each object dynamically makes it easier to add a decoration mode than to generate a subclass.
Component is an object interface that can dynamically add responsibilities to these objects. Concretecomponent defines a specific object. You can also add some responsibilities to this object. Decorator: A decorative abstract class that inherits component and extends the functionality of the component class from external classes. For component, you do not need to know the existence of decoratro. As for concretedecorator, It is a specific decoration object and serves to add responsibilities to component.
Chapter 4 Decoration Mode