Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Parent variable = new Child();
- public class ReportBuilder {
- public ReportBuilder() {
- }
- public createReport(Report report) {
- data = report.collectData();
- excelFile = this.makeExcel(report, report.template());
- this.publishAndSave(excelFile);
- }
- }
- abstract class Report {
- DataContainer collectData();
- String template()
- }
- class ReportA extends Report {
- DataContainer collectData() {
- // собираем одни данные
- }
- String template() {
- return 'file1.xls';
- }
- }
- class ReportB extends Report {
- DataContainer collectData() {
- // собираем одни данные
- }
- String template() {
- return 'file1.xls';
- }
- }
- reportBuilder = new ReportBuilder();
- reportBuilder.createReport(new ReportA());
- reportBuilder.createReport(new ReportB());
- class Child {
- private int age;
- @Override
- String toString() {
- return "age is "+age;
- }
- }
- Child child=new Child();
- Object myObject=child;
- System.out.println(child); //печатаем объект Child
- System.out.println(myObject); //печатаем объект Object
Add Comment
Please, Sign In to add comment