1 package test_24_1; 2 3 public interface Target { 4 5 public void method1(); 6 7 public void method2(); 8 }
1 package test_24_1; 2 3 public class Adaptee { 4 5 public void method1() { 6 7 System.out.println("Adaptee method1()"); 8 } 9 }
1 package test_24_1; 2 3 public class Adapter extends Adaptee implements Target { 4 5 @Override 6 public void method2() { 7 8 System.out.println("Adapter method2()"); 9 } 10 11 }
1 package test_24_1; 2 3 public class AdapterTest { 4 5 public static void main(String[] args) { 6 7 Adapter adapter = new Adapter(); 8 9 adapter.method1(); 10 11 adapter.method2(); 12 } 13 }
结果如下:
Adaptee method1()
Adapter method2()
[20-05-30][Design Model 6]ADAPTER 1
原文:https://www.cnblogs.com/mirai3usi9/p/12993432.html