public class InkHebei implements Ink {
public String getInkColor() {
// TODO Auto-generated method stub
return "蓝色";
}
}
public class InkQingdao implements Ink {
public String getInkColor() {
// TODO Auto-generated method stub
return "红色";
}
}
public class PaperBeijing implements Paper{
public String getPaperSize() {
// TODO Auto-generated method stub
return "A4";
}
}
public class PaperShanghai implements Paper{
public String getPaperSize() {
return "A6";
}
}
public class PrintHp implements Print {
public void print(Paper paper, Ink ink){
System.out.println(“在”+paper.getPaperSize()+”纸打印”);
}
}
public class PrintOther implements Print {
public void print(Paper paper,Ink ink){
System.out.println(“在”+paper.getPaperSize()+”用”+ink.getInkColor()+”纸打印”);
}
}
//方法的调用
public class InkFactory {
public static Ink createink(){
return new InkHebei();
}
}
public class PaperFactory {
public static Paper createpaper(){
return new PaperShanghai();
}
}
//测试类
public class Test {
public static void main(String[] args) {
Paper paper= PaperFactory.createpaper();
Ink ink=InkFactory.createink();
Print print=new PrintOther();
print.print(paper,ink);
}
}