[20-05-30][Design Model 7]ADAPTER 2
作者:互联网
1 package test_24_2; 2 3 public interface Target { 4 5 void method1(); 6 7 void method2(); 8 }
1 package test_24_2; 2 3 public class Adaptee { 4 5 public void method1() { 6 7 System.out.println("Adaptee method1()"); 8 } 9 }
1 package test_24_2; 2 3 public class Adapter implements Target { 4 5 private Adaptee adaptee; 6 7 public Adapter(Adaptee adaptee) { 8 this.adaptee = adaptee; 9 } 10 11 public void method1() { 12 this.adaptee.method1(); 13 } 14 15 public void method2() { 16 17 System.out.println("Adapter method2()"); 18 } 19 }
1 package test_24_2; 2 3 public class AdapterTest { 4 5 public static void main(String[] args) { 6 Adapter adapter = new Adapter(new Adaptee()); 7 8 adapter.method1(); 9 10 adapter.method2(); 11 } 12 }
结果如下:
Adaptee method1()
Adapter method2()
标签:Adapter,20,method1,void,05,public,method2,Adaptee,ADAPTER 来源: https://www.cnblogs.com/mirai3usi9/p/12993627.html