016-003-011
Template Method Pattern
Hard
Problem Description
Template Method Pattern
In this problem: You will implement the Template Method pattern in an abstract class DataProcessor, defining the processing skeleton while subclasses CsvProcessor and JsonProcessor provide concrete implementations.
Learning Objective: Understand the Template Method pattern as a design technique using abstract classes
Overview
The DataProcessor abstract class defines the processing skeleton (read, transform, write) in its process() method. Each step is delegated to subclasses as abstract methods.
Specifications
DataProcessorabstract class:process(): template method (callsreadData(),transformData(),writeData()in order)readData(): abstract method (outputs the read step)transformData(): abstract method (outputs the transform step)writeData(): abstract method (outputs the write step)
CsvProcessor: outputs CSV-specific processing for each stepJsonProcessor: outputs JSON-specific processing for each step- In Main, call
process()on both processors
Output Format
--- CSV Processing ---
Reading CSV file
Converting CSV to records
Writing records to database
--- JSON Processing ---
Reading JSON file
Parsing JSON to objects
Writing objects to API
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up