类适配器模式
package com.life.design.adaper.classadapter; public interface IVoltage5V { public int output5V(); }
package com.life.design.adaper.classadapter; public class Voltage220V { public int output220V() { int src = 220; System.out.println("电压=" + src + "伏"); return src; } }
package com.life.design.adaper.classadapter; public class VoltageAdapter extends Voltage220V implements IVoltage5V { @Override public int output5V() { int srcV = output220V(); int dstV = srcV / 44 ; return dstV; } }