Guest User

Untitled

a guest
Jan 23rd, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Parent variable = new Child();
  2.  
  3. public class ReportBuilder {
  4. public ReportBuilder() {
  5. }
  6.  
  7. public createReport(Report report) {
  8. data = report.collectData();
  9. excelFile = this.makeExcel(report, report.template());
  10. this.publishAndSave(excelFile);
  11. }
  12. }
  13.  
  14. abstract class Report {
  15. DataContainer collectData();
  16. String template()
  17. }
  18.  
  19. class ReportA extends Report {
  20. DataContainer collectData() {
  21. // собираем одни данные
  22. }
  23.  
  24. String template() {
  25. return 'file1.xls';
  26. }
  27. }
  28.  
  29. class ReportB extends Report {
  30. DataContainer collectData() {
  31. // собираем одни данные
  32. }
  33.  
  34. String template() {
  35. return 'file1.xls';
  36. }
  37. }
  38.  
  39. reportBuilder = new ReportBuilder();
  40. reportBuilder.createReport(new ReportA());
  41. reportBuilder.createReport(new ReportB());
  42.  
  43. class Child {
  44. private int age;
  45.  
  46. @Override
  47. String toString() {
  48. return "age is "+age;
  49. }
  50. }
  51.  
  52.  
  53. Child child=new Child();
  54. Object myObject=child;
  55. System.out.println(child); //печатаем объект Child
  56. System.out.println(myObject); //печатаем объект Object
Add Comment
Please, Sign In to add comment