Detailed explanation of the principle and usage of combination mode of Java design mode
This paper describes the combination pattern of Java design pattern. Share with you for your reference, as follows:
Combination (relationship between whole and part): different but related objects are combined into a tree structure to realize the "part whole" hierarchical structure, so that users can use single objects and combined objects consistently.
*Mode role composition:
1. Component object: it is the object interface in the composition and the interface common to all classes. It is used to uniformly define the parts of the whole.
2. Leaf object: part of the whole without a lower level.
3. Composite object: it is used to store sub components and implement some related operations in the component interface.
Take the composition of the company as an example. For example, the company has a head office, branches and offices. Form a tree structure.
Generally, the combination mode is used when it is necessary to represent the overall and partial hierarchy of objects or ignore the difference between the overall and partial objects of combination, and uniformly use the departments in the whole.
For more Java related content, interested readers can view the special topics of this site: Java data structure and algorithm tutorial, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills