(According to the msdn webcast courses)
Started with Russian doll. The doll contains another one, and the last one does not contain any one.
The combination mode uses a tree structure to implement ubiquitous object containers. It converts a complex one-to-many relationship into a simple one-to-one relationship, so that a batch of objects can be processed in a consistent manner, make the customerProgramYou do not need to care about the specific implementation of the Object content.
Decoupling the customer program from the object is the core idea of the combination mode. After decoupling, the client program can only interact with interfaces on the upper layer of the object.
A bad design scheme:
When one-to-many relationships are exposed to the outside world, the customer program must process one-to-one relationships and one-to-many relationships.
The improved solution adopts the composite design mode:
Upgrade the method unique to the parent class of the container object to ensure that the client program can use a consistent solution to process the object. In addition, two tasks are completed in the process method:
1. Complete the transaction processing;
2. cyclically process events in included sub-objects.
This transfers the original recursive call task in the customer program to the cyclic call within the object. Greatly reduced Coupling Relationships andCodeComplexity.
Note: In the sample code, the add and remove operations are used to include members. We recommend that you use the method in the UML diagram to manage objects using ilist, so as to automatically implement the add, remove, and other operation methods.
Common Structure-like menus, windows, and control structures in ASP. NET.