package Fill.vice.test;
import java.util.Date;
public class TestDemo {
public static void main(String[] args) {
B b=new Bac();
Aadapter ad=new Aadapter(b);
test(ad);
}
public static void test(A a){//这里只接收的a
a.say();
}
}
/*适配器模式
*
* 将一个接口转换成另一个接口。使原本不兼容,不能在一起工作的类在一起工作
*
*/
//适配A
class Aadapter implements A{
private B b;
public Aadapter(B b){
this.b=b;
}
public void say(){
b.action();
}
}
interface A{
public void say();
}
interface B{
public void action();
}
class Aac implements A{
public void say(){
System.out.print("a 的专属");
}
}
class Bac implements B{
public void action(){
System.out.println("b的专门属性");
}
}
适配器模式
最新推荐文章于 2022-11-22 15:10:10 发布