Design Patterns involved in Android
1. Adapter mode: Adapter of ListView or GridView
Summary: Different data providers use an adapter to provide services to an identical customer.
2. Builder mode: Alertdialog.builder
Summary: Each part can be constructed in a step.
3, Command mode: Handler.post after Handler.handlemessage
Description: The request is encapsulated into an object to send out, convenient to customize, queue, Cancel.
4, enjoy meta-mode: Message.obtainmessage by reusing the message object to avoid the frequent creation and destruction of a large number of message objects.
Summary: Use shared technology to effectively support a large number of fine-grained objects.
5, iterator mode: such as through the Hashtable.elements method can get a enumeration, and then through this enumeration access to the data in the Hashtable, without concern about the data storage in the Hashtable way.
Summary: Provides a way to sequentially access all data in a data collection without exposing an internal representation of the object.
6, Memo mode: Activity of Onsaveinstancestate and onrestoreinstancestate is through the bundle of this serialized data structure to store the state of activity, as for the data structure stored in it, These two methods do not care
Summary: You do not need to know the internal structure of an object to back up the state of an object for later recovery.
7, Observer mode: We can use Baseadapter.registerdatasetobserver and Baseadapter.unregisterdatasetobserver two method to register to Baseadater, Unregisters a datasetobserver. In this process, DATASETOBSERVER is an observer, and once it finds that baseadapter internal data has variables, The Datasetobserver implementation class is notified through callback methods Datasetobserver.onchanged and datasetobserver.oninvalidated. Event notification is also an observer pattern
Summary: When an object changes, all objects that depend on it are automatically changed accordingly.
8, prototype mode: For example, we need a bitmap of several different formats: argb_8888, rgb_565, argb_4444, Alapha_8 and so on. Then we can first create a argb_8888 bitmap as a prototype, based on it, by calling Bitmap.copy (Config) to create several other formats of bitmap. Another example is that all objects in Java have a method named Clone, which is synonymous with the prototype pattern.
Summary: In the system to create a large number of objects, these objects have almost identical functionality, but only a little bit different in detail.
9, Proxy mode: similar to the iOS development of the delegate delegation mode, all the Aidl is a proxy mode example. Assuming that an activity a goes to bind a service s, each method in a call to S is actually brokered by the system's binder mechanism, and then calls the corresponding method in S. The binder mechanism acts as an agent.
Summary: Provides a proxy for other objects to control access to this object.
10, State mode: View.onvisibilitychanged method, is to provide a state mode implementation, allowing the visibility of the View to be changed, the execution of the Onvisibilitychanged method of action.
Summary: Behavior changes when the state changes.
11. Policy mode:
For example: Java.util.List is defined as an Add, delete (remove), change (set), check (INDEXOF) strategy, as for the implementation of this strategy ArrayList, LinkedList and other classes, only in the implementation of the use of different algorithms. But because of their strategy, regardless of the speed of the case, the use of the full can be replaced with each other.
Summary: Defines a series of objects that encapsulate algorithms, behaviors, and they can be replaced by each other.
12. Mediator Mode
Summary: When an operation of an object requires the M method of invoking N objects to complete, the invocation process is encapsulated and becomes a mediator
Example: the implementation logic of the Resource.getdrawable method is this: Create a cache to hold all the loaded, if the getdrawable passed in the ID corresponding to the drawable has not been loaded before, then it will be based on the ID of the corresponding resource type, respectively, call the XML parsing or by reading the picture resource file in the package to create the drawable.
and resource.getdrawable the role of a mediator by encapsulating operations involving multiple objects and multiple logic into a single method.
13. Abstract Factory mode
Use of DAO and service
Interview with Android design mode