Composite mode



 

GOF Intent: To combine objects into a tree structure to represent a hierarchy of "parts of the whole". (form a tree structure)

 

Role:

1. Component is a unified interface that, where appropriate, implements common default behavior. Declare an interface for accessing multiple leaves.

2.Leaf is the combined object.

3.Composite is a combiner, has a list list, used to store leaf components, and implements operations related to subcomponents in the Component interface, such as adding (add) and deleting (remove).

 

Implementation: composite is the combiner or combiner (tree-like node), leaf is the combiner (tree-like node). Both implement the same interface.

 

applicability:

Composite mode applies when:

1. You want to represent the part-whole hierarchy of objects

2. You want users to ignore the difference between composite objects and individual objects, and users will use the same interface uniformly.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326881436&siteId=291194637