Android Design Pattern series (1)-SDK source code combination pattern, android-sdk
The application of the combination mode in Android is everywhere, that is, the use of the View and ViewGroup classes. In android UI design, almost all widgets and layout classes depend on these two classes.
Composite Pattern is a very clever mode. Almost all object-oriented systems are applied to the combination mode.
1. Intention
Combine the object View and ViewGroup into a tree structure to represent the "part-whole" hierarchy (View can be used as part of the ViewGroup ).
The combination mode ensures consistency between the use of a single object View and a composite object ViewGroup.
Hot words:Part-whole Container-content tree structure consistency leaf synthesis security transparency
2. Structure
For the actual situation of View and ViewGroup, we select a safe combination mode (add, remove, and getChild methods to the combination object), add a few comments, and modify it:
3. Code
View class implementation:
Public class View {// ...... // irrelevant methods are omitted}
ViewGroup implementation:
public abstract class ViewGroup extends View{ /** * Adds a child view. */ public void addView(View child) { //... } public void removeView(View view) { //... } /** * Returns the view at the specified position in the group. */ public View getChildAt(int index) { try { return mChildren[index]; } catch (IndexOutOfBoundsException ex) { return null; } } //other methods}
4. Results
(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). Simplify customer code. 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.
(5) Make your design more general.
Is the android source code package different from the android SDK development?
Android source code development is generally used by mobile phone manufacturers, because it involves modifying the source code and designing a UI suitable for your mobile phone.
Android SDK is used to develop its own applications based on the standard android sdk.
Pai_^
In Java, there are 23 design patterns. Which of the following are used in Android?
The so-called mode is actually a common idea. After you get familiar with it, you won't even consider what it is. There are more than 23 design patterns.