voltage is the target interface, and the 220v voltage is the Adaptee class, and switching the voltage from 220V to 5V is adapter.
Class 2.2 Adapter Mode:
/**
* Target role
/public interface Fivevolt {public
int getVolt5 ();
}
/**
* adaptee role, the object that needs to be converted
/public class Volt22
; }} test publicclasstest{ publicstaticvoidmain (String[]args) { jotterjt =newjotter ();powersupplydevice Powersupplydevice=newpowersupplydevice (); Voltageadapteradapter=newmyvoltageadapter (Powersupplydevice); jt.setadapter (adapter); jt.inputvoltage (); }} Execution results Here, let's summarize the advantages and disadvantages of the adapter pattern:Advantages:1, two different interfaces can b
Android source code: ListView adapter ModeMode definition
The adapter mode converts an interface of a class into another interface that the client expects, so that the two classes that cannot work together due to interface mismatch can work together.Use Cases
Using Power interfaces as an example, the power supply of laptops generally accepts 5 V voltage, but the
involved in the class adapter is as follows:
Target role: the interface that the client expects. This is because the class adapter is discussed here, and because of the attributes inherited by the Java language, the target role cannot be a class.
Source (adaptee) role: the interface to be adapted is the object to
socket interface, the example is very simple and clear. Of course, this example is very simple, want to learn the idea: The original class is not modified on the basis of the original class after the expansion of the use of the new target system.Object Adapter ModeObject Adapter mode as an example of a view I wrote a few years ago:
An introduction to Adapter mode
What is adapter mode
Defined
Classification
What scenarios the adapter applies To
Two adapter mode applications in the Android framework
Listviewbaseada
Design Mode in Android-adapter ModeAdapter Mode
From the name, we can see that the adapter is a compatible Method for interface mismatch,Suppose we have an existing class Adaptee, and some of them have existing and implemented Methods methodA. But the customer does not want to call this class, but wants to call a specific interface, such as the
, this adapter way, the coupling is lower.Default adapter ModeThe adapter also has a third mode that looks different than the two adapter modes above,For an interface that defines more methods, it is cumbersome to implement so many methods when we implement the interface. Secondly, there are some ways that we do not ne
For Android Developers, the adapter mode is quite familiar. Many applications use the adapter mode, such as listview, directly or indirectly every day.Listview is used to display list data. However, as a list dataset, there are many forms, including array and cursor. We need the corresponding adapter as a bridge, proce
Exploring the adapter mode of Android DevelopmentWhen developing Android, we often connect the data and UI objects through the Adapter. controls such as spinner and ListView can be customized by the Adapter to enrich them. The adapter
Adapter mode used in android
Adapter mode ):
The adapter mode is a behavior mode that converts an interface of a class to another interface expected, this allows the two classes that cannot work together because of interfaces to work together. The adapter mode can be a class
labels, for example :Android:layout_width= "Match_parent".../>3.Adapter Adapter mode,Adapter itself is an interface, General Adapter for some components to provide data, similar to the principle of charger and charging target, The phone has a mobile phone
initiated in the activity environment, the following label is setintent.setflags (Intent.flag_activity_new_task); if(build.version.sdk_int>= -) {//is the interpretation version above 7.0 ?//Parameter 1 context, parameter 2 provider the host address and the configuration file remain consistent with parameter 3 shared filesUri Apkuri =fileprovider.geturiforfile (Context,"Com.xxx.xxxxx.fileprovider", file); //Add this sentence to indicate the file that the URI represents for temporary authorizatio
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.