Design design Pattern C # language Description--synthesis (composite) mode
* This article refers to "Java and the pattern" part of the content, suitable for the design pattern of beginners.
The composite model pattern belongs to the structure pattern of objects, sometimes called partial-whole mode. The compositing pattern organizes objects into a tree structure that can be used to describe the relationship between the whole and the part. A compositing pattern enables a client to treat a simple element to the same as a composite element. such as folders and files are typical applications of synthetic patterns. According to the difference of the interface of the pattern, the synthetic mode can be divided into two kinds: safe type and transparent type.
The safe synthesis mode requires that the method of managing aggregation only appears in the branch component class, but not in the leaf component class. The class diagram looks like this:
involves three roles:
Abstract widget (Component): This is an abstract role that defines a common interface and its default behavior for the participating objects, and can be used to manage all of the child objects. A composite object usually treats a child object that it contains as a component object of type. In the safe synthesis mode, the component role does not define a method for managing the child objects, which is given by the tree Component object.
Leaf component (leaf): A leaf object is an object that has no subordinate child objects, defining the behavior of the original object participating in the composition.
Branch Widget (Composite): An object that represents a subordinate child object that participates in a combination. The branch widget class gives all the methods for managing child objects, such as Add (), Remove (), and so on.
In contrast to the safe mode of synthesis, the transparent synthesis pattern requires that all concrete component classes, whether tree or leaf members, conform to a fixed interface. The class diagram looks like this:
Abstract widget (Component): This is an abstract role that defines a common interface and its default behavior for the participating objects, and can be used to manage all of the child objects. To provide an interface to standardize access to and manage interfaces for the underlying components, including add (), Remove ().
Leaf component (leaf): A leaf object is an object that has no subordinate child objects, defining the behavior of the original object participating in the composition. The leaf object gives a mediocre implementation of the methods such as Add (), Remove ().
Branch Widget (Composite): An object that represents a subordinate child object that participates in a combination. Defines the behavior of such an object.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.