开发打印机
墨盒:彩色,黑白纸张类型:A4,B5墨盒和纸张都不是打印机厂商提供的打印机厂商要兼容市场上的墨盒,纸张
墨盒接口
package .demo1;public interface InkBox {public String color();}
黑色
package .demo1;public class BlackBox implements InkBox{@Overridepublic String color() {// TODO Auto-generated method stubreturn "黑白墨盒";}}
彩色
package .demo1;public class BlackBox implements InkBox{@Overridepublic String color() {// TODO Auto-generated method stubreturn "黑白墨盒";}}
纸张接口
package .demo1;public interface Paper {public String size();}
A4
package .demo1;public class A4Paper implements Paper{@Overridepublic String size() {// TODO Auto-generated method stubreturn "A4纸张";}}
B5
package .demo1;public class B5Paper implements Paper{@Overridepublic String size() {// TODO Auto-generated method stubreturn "B5纸张";}}
打印机厂商
package .demo1;public class Printer {public static void print(Paper paper, InkBox inkBox) {System.out.println("使用"+inkBox.color()+"在"+paper.size()+"上打印");}}
测试
package .demo1;public class Test {public static void main(String[] args) {Printer.print(new B5Paper(), new ColorfulBox());Printer.print(new A4Paper(), new BlackBox());}}
面向接口编程开发打印机墨盒:彩色 黑白纸张类型:A4 B5墨盒和纸张都不是打印机厂商提供的打印机厂商要兼容市场上的墨盒 纸张