Skip to content

Latest commit

 

History

History
97 lines (79 loc) · 2.84 KB

File metadata and controls

97 lines (79 loc) · 2.84 KB

Grade And Reports Example

UML To Implement

Code

Report Interface

abstract class Report {
  String showPrimaryGradeReport();
  String showSecondaryGradeReport();
  String showGrade3Report();
}

Report Implementations

class HTMLReport implements Report {
  String showPrimaryGradeReport() =>
      "<h1>This is a grade Primary report</h1>\n";
  String showSecondaryGradeReport() =>
      "<h1>This is a grade Secondary report</h1>\n";
  String showGrade3Report() => "<h1>This is a grade 3 report</h1>\n";
}

class PlainTextReport implements Report {
  String showPrimaryGradeReport() => "This is a grade Primary report\n";
  String showSecondaryGradeReport() => "This is a grade Secondary report\n";
  String showGrade3Report() => "This is a grade 3 report\n";
}

class XMLReport implements Report {
  String showPrimaryGradeReport() =>
      "<StudentReport>This is a grade Primary report</StudentReport>\n";
  String showSecondaryGradeReport() =>
      "<StudentReport>This is a grade Secondary report</StudentReport>\n";
  String showGrade3Report() =>
      "<StudentReport>This is a grade 3 report</StudentReport>\n";
}

Grade Interface

Create an abstract class Grade

abstract class Grade {
 Report report;
 Grade(this.report);
 String showReport();
}

Grade SubClasses

class PrimaryGrade extends Grade {
  PrimaryGrade(Report report) : super(report);

  @override
  String showReport() => report.showPrimaryGradeReport();
}

class SecondaryGrade extends Grade {
  SecondaryGrade(Report report) : super(report);

  @override
  String showReport() => report.showSecondaryGradeReport();
}

class Grade3Report extends Grade {
  Grade3Report(Report report) : super(report);

  @override
  String showReport() => report.showGrade3Report();
}

main()

  // Show any Report Type You Need
  // here I choosed  Html Report
  Report HtmlReport = HTMLReport();

  // Then inject Report type to what grade you want to show
  // here I choosed  Primary
  Grade primaryGrade = PrimaryGrade(HtmlReport);

  print(primaryGrade.showReport());

Output.

<h1>This is a grade Primary report</h1>