Adapter mode (applicable scenarios, the transformation of the old system, and some codes cannot be modified, and compatibility processing is required)
original usb interface
public interface Usb { void input(); }
The original calling method
public class Customer { public void input(Usb usb){ usb.input(); } }
the method you want to call now
public class Ps2 {
public void ps2Input(){
System.out.println("ps2输入");
}
}
Transition class created in the middle
public class SwUsb2Ps2 implements Usb{ private static Ps2 ps2 = new Ps2(); @Override public void input() { ps2.ps2Input(); } }