Android and design patterns-Composite mode and androidcomposite

Source: Internet
Author: User

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.

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.