Android and design patterns-Composite mode and androidcomposite
Definition(GoF design patterns): combines objects into a tree structure to represent a "partial whole" hierarchy. The combination mode ensures consistency between the use of a single object and a composite object.
Involved roles
1. Component: (View) is the object declaration interface in the combination. When appropriate, it implements the default behavior of interfaces common to all classes. Declare an interface to access and manage Component sub-parts.
2. Leaf: (TextView and custom View) indicates the Leaf node object in the combination. The Leaf node does not have any subnode (that is, the View cannot be added to the View ).
3. composite :( ViewGroup and its subclass) defines the behavior of a branch node to store sub-parts. In the Component Interface, operations related to sub-parts are implemented, such as addView and getViewAt) and removeView.
Applicability
The Composite mode is applicable in the following situations:
1. You want to represent the part of the object-the overall hierarchy
2. You want to ignore the differences between a composite object and a single object. You will use all objects in the composite structure in a unified manner.
Summary
(1). Structural Mode
(2) defines a class hierarchy that contains basic objects and composite objects. This structure can flexibly control the use of basic objects and composite objects.
(3). The basic objects and composite objects are consistent, so you do not need to distinguish them.
(4) makes it easier to add new types of components.
Not yet resumed. please correct me if there is anything wrong.