- package com.visionsky.DesignPattern;
- interface Target {
- void Request();
- }
- class Adaptee {
- void SpecificRequst() {
- System.out.println("Adaptee's SpecificRequst");
- }
- }
- class Adapter extends Adaptee implements Target
- {
- @Override
- public void Request() {
- System.out.println("Adapter's Request");
- super.SpecificRequst();
- }
- }
- public class AdapterDemo {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Target t=new Adapter();
- t.Request();
- }
- }
- package com.visionsky.DesignPattern;
- interface Target {
- void Request();
- }
- class Adaptee {
- void SpecificRequst() {
- System.out.println("Adaptee's SpecificRequst");
- }
- }
- class Adapter implements Target
- {
- private Adaptee adaptee;
- public Adapter()
- {
- this.adaptee=new Adaptee();
- }
- @Override
- public void Request() {
- System.out.println("Adapter's Request");
- adaptee.SpecificRequst();
- }
- }
- public class AdapterDemo {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Target t=new Adapter();
- t.Request();
- }
- }
- package com.visionsky.DesignPattern;
- public class AdaterDemoInLife {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- MobilePowerAdapter mpa=new MobilePowerAdapter();
- mpa.GetPower10V();
- }
- }
- interface ITarget {
- int GetPower10V();
- }
- class Power {
- int GetPower220V() {
- return 220;
- }
- }
- class MobilePowerAdapter implements ITarget
- {
- private Power power;
- public MobilePowerAdapter( ) {
- this.power = new Power();
- }
- @Override
- public int GetPower10V() {
- // TODO Auto-generated method stub
- power.GetPower220V();
- //将220v转变成10v,具体做法就不写了, 大家明白就行
- return 10;
- }
- }