public interface China220VInterface {
public void connect();
}
public class Chinae220VInterfaceImpl implements China220VInterface {
@Override
public void connect() {
System.out.println(“中国220v电源开始工作”);
}
}
public interface JP110VInterface {
public void connect();
}
public class JPInterfaceImpl implements JP110VInterface {
@Override
public void connect() {
System.out.println(“日本110v开始工作”);
}
}
public class ElectricCooker {
private JP110VInterface ap110VInterface;
ElectricCooker (JP110VInterface ap110VInterface){
this.ap110VInterface=ap110VInterface;
}
public void work(){
ap110VInterface.connect();;
System.out.print(“电饭煲开始工作”);
}
public void cooker(){
ap110VInterface.connect();
System.out.println(“电饭煲开始煮蛋”);
}
}
public class PowerAdapter implements JP110VInterface {
private China220VInterface china220VInterface;
PowerAdapter(China220VInterface china220VInterface){
this.china220VInterface=china220VInterface;
}
@Override
public void connect() {
china220VInterface.connect();
}
}
public class AdapterTest {
public static void main(String[] args) {
China220VInterface china220VInterface=new Chinae220VInterfaceImpl();
PowerAdapter powerAdapter=new PowerAdapter(china220VInterface);
ElectricCooker electricCooker=new ElectricCooker(powerAdapter);
electricCooker.work();
electricCooker.cooker();
}
}
2810

被折叠的 条评论
为什么被折叠?



