Android and design mode--combination (Composite) mode

Source: Internet
Author: User

definition (GoF design mode): Combines objects into a tree structure to represent a hierarchical structure of "partial whole." The combined mode makes the user consistent with the use of individual objects and composite objects.


  involves roles
1. Component: (View) is an object declaration interface in a composition that implements the default behavior of all classes common interfaces, where appropriate. Declares an interface for accessing and managing component subassemblies.
2.Leaf: (TextView, Custom view) represents the leaf node object in the composition, and the leaf node has no sub-nodes (that is, you cannot add view within the view).
3.Composite: (ViewGroup and its subclasses) defines a sub-point behavior that is used to store subassemblies and to implement operations related to subassemblies in the component interface, such as increasing (AddView), acquiring (Getviewat), and deleting (Removeview) and so on.

applicability

1. You want to represent the part of the object-the overall hierarchy
2. You want users to ignore the difference between a combined object and a single object, and the user will use all the objects in the composite structure uniformly.

Summarize

(1). Structural mode

(2). Defines a class hierarchy that contains Basic objects and composite objects. This structure provides the flexibility to control the use of basic objects and composite objects.

(3). The base object and the composition object are consistent, and the user does not have to differentiate between them.

(4). Makes it easier to add new types of components.


Please correct me if there is any wrong place to be continued.

Android and design mode--combination (Composite) mode

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.