2019.2.18接口2

Posted zhangchuanfeng1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019.2.18接口2相关的知识,希望对你有一定的参考价值。

技术图片

CPU:

package com.cpu;

public interface Cpu {
    public String xinHao();
    public String zhuPin();
}

CPU型号和主频:

package com.cpu;

public class CpuBrand implements Cpu{

    @Override
    public String xinHao() {
        // TODO Auto-generated method stub
        return "Intel";
    }

    @Override
    public String zhuPin() {
        // TODO Auto-generated method stub
        return "3.8GHz";
    }

}

ems:

package com.EMS;

public interface Ems {
    public String EMS();
}

ems容量:

package com.EMS;

public class EmsCapacity implements Ems {

    @Override
    public String EMS() {
        // TODO Auto-generated method stub
        return "3000GB";
    }

}

硬盘:

package com.HardDisk;

public interface HardDisk {
    public String hardDisk();
}

硬盘容量:

package com.HardDisk;

public class HardDiskCapacity implements HardDisk {

    @Override
    public String hardDisk() {
        // TODO Auto-generated method stub
        return "4GB";
    }

}

电脑类:

package com.master;

import com.EMS.Ems;
import com.HardDisk.HardDisk;
import com.cpu.Cpu;
/**
 * 电脑类
 */
public class Computer {
    private Cpu cpu;
    private Ems ems;
    private HardDisk hardDisk;
    
    public Cpu getCpu() {
        return cpu;
    }
    public void setCpu(Cpu cpu) {
        this.cpu = cpu;
    }
    public Ems getEms() {
        return ems;
    }
    public void setEms(Ems ems) {
        this.ems = ems;
    }
    public HardDisk getHardDisk() {
        return hardDisk;
    }
    public void setHardDisk(HardDisk hardDisk) {
        this.hardDisk = hardDisk;
    }
    
    public void print() {
        System.out.println("计算机的信息如下:");
        System.out.println("CPU的品牌是:"+cpu.xinHao()+",主频是"+cpu.zhuPin());
        System.out.println("硬盘容量是:"+ems.EMS());
        System.out.println("内存容量是:"+hardDisk.hardDisk());
    }
    
}

测试类:

package com.master;

import com.EMS.Ems;
import com.EMS.EmsCapacity;
import com.HardDisk.HardDisk;
import com.HardDisk.HardDiskCapacity;
import com.cpu.Cpu;
import com.cpu.CpuBrand;

public class TestComputer {
    public static void main(String[] args) {
        Cpu cpu = new CpuBrand();
        Ems ems = new EmsCapacity();
        HardDisk hardDisk = new HardDiskCapacity();
        Computer computer = new Computer();
        
        computer.setCpu(cpu);
        computer.setEms(ems);
        computer.setHardDisk(hardDisk);
        
        computer.print();
    }
}

输出:

技术图片

 

以上是关于2019.2.18接口2的主要内容,如果未能解决你的问题,请参考以下文章

与另一个片段通信的片段接口

从父片段到选项卡片段的接口侦听器不起作用

Express实战 - 应用案例- realworld-API - 路由设计 - mongoose - 数据验证 - 密码加密 - 登录接口 - 身份认证 - token - 增删改查API(代码片段

java 代码片段

无法通过接口获取与片段通信的活动

将接口从片段传递到kotlin中的活动