Template Method for Reports

Hard ⏱ 18 min 34% acceptance ★★★★☆ 4.4
Base class Report defines the template method render() returning header() + '|' + body() where header() returns 'REPORT' but body() raises NotImplementedError. Subclass SalesReport supplies body() returning 'sales=90'. The base fixes the skeleton; children fill the blanks.

Examples

Example 1
Input
SalesReport().render()
Output
'REPORT|sales=90'
Explanation

The template assembled inherited and overridden pieces.

Constraints

  • render lives only on the base.
  • body on the base raises NotImplementedError.

Topics

OOPtemplate method

Companies

SAPSalesforceZoho

Hints

Hint 1

The base calls self.body() — dispatch finds the child version.

Hint 2

Do not override render in the subclass.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.