类适配器模式

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;
    }
}

 

posted on 2022-04-19 20:25  金满仓  阅读(10)  评论(0编辑  收藏  举报

导航