You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
524 B

// 原始错误代码:违反开闭原则
public class OldReport {
public void generate(String type){
if(type.equals("PDF")){
System.out.println("生成PDF报表");
}else if(type.equals("Excel")){
System.out.println("生成Excel报表");
}
// 缺点:新增格式必须修改这里的if else
}
public static void main(String[] args) {
OldReport r = new OldReport();
r.generate("PDF");
r.generate("Excel");
}
}