对象适配器模式
package com.life.design.adaper.objectadapter; public interface IVoltage5V { public int output5V(); }
package com.life.design.adaper.objectadapter; public class Voltage220V { public int output220V() { int src = 220; System.out.println("电压=" + src + "伏"); return src; } }
package com.life.design.adaper.objectadapter; public class VoltageAdapter implements IVoltage5V { private Voltage220V voltage220V; public VoltageAdapter(Voltage220V voltage220v) { this.voltage220V = voltage220v; } @Override public int output5V() { int dst = 0; if(null != voltage220V) { int src = voltage220V.output220V(); System.out.println("使用对象适配器,进行适配~~"); dst = src / 44; System.out.println("适配完成,输出的电压为=" + dst); } return dst; } }