Frequently-used problems: for example, cell phones, MP3, and computer chargers, the conversion connectors are equivalent to one adapter. This data conversion is similar to the adapter mode.
Package myadapter;/*** @ description: adapter mode * @ author Potter * @ date 11:17:12 * @ version V1.0 */public class app {public static void main (string [] ARGs) {adapter = new adapter (); adapter. setpower (New Power (220); device phone = new phone (); phone. AC (adapter );}}
Power supply:
Package myadapter;/*** @ Description: Power Supply * @ author Potter * @ date 11:20:35 * @ version V1.0 */public class power {int V; // voltage public power (INT v) {This. V = V ;}}
Adapter class:
Package myadapter;/*** @ Description: * @ author Potter * @ date 2012-8-14 11:18:10 * @ version V1.0 */public class adapter {power; /** convert to an appropriate power supply to charge the device **/Public int convert (device) {If (device instanceof MP3) {power. V = 20;} else if (device instanceof phone) {power. V = 25;} return power. v;} public power getpower () {return power;} public void setpower (Power) {This. power = power ;}}
Device abstract class:
Package myadapter;/*** @ description: * @ author Potter * @ date 09:59:58 * @ version V1.0 */public abstract class device {/** charge * @ Param p voltage */public abstract void AC (adapter) ;}
MP3:
Package myadapter;/*** @ Description: * @ author Potter * @ date 11:18:39 * @ version V1.0 */public class MP3 extends device {@ overridepublic void AC (adapter) {system. out. println ("map3 charging, voltage:" + adapter. convert (this) + "v ");}}
Phone:
Package myadapter;/*** @ Description: * @ author Potter * @ date 11:18:29 * @ version V1.0 */public class phone extends device {@ overridepublic void AC (adapter) {system. out. println ("mobile phone charging, voltage is" + adapter. convert (this) + "v ");}}
Print result:
Mobile phone charging with a voltage of 25 V
This is my understanding of the adapter mode. If you think that your younger brother is not correct, please give pointers. Thank you.