2 changed files with 23 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||
public class ExcelReport implements ReportInter{ |
|||
@Override |
|||
public void generate() { |
|||
System.out.println("生成Excel报表"); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
// 原始错误代码:违反开闭原则
|
|||
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"); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue