适配器模式(Adapter)

适配器模式

 public class Current { public void use220V(){ System.out.println("使用220V电压"); } } public class Adapter extends Current { private Current current; public Adapter(Current current) { this.current=current; } public void use18V(){ System.out.println("使用适配器"); this.current.use220V(); } } public class Test { public static void main(String[] args) { Adapter adapter = new Adapter(new Current()); adapter.use18V(); } }

 

你可能感兴趣的:(适配器模式(Adapter))