Grokking Design Patterns for Engineers and Managers
0% completed
Template Method Pattern
The Template Method Pattern fixes the order of the steps of an algorithm in a base class, and lets subclasses supply the steps that differ.
A data import job always does the same five things. It reads the rows, parses each one, validates the result, saves it, and reports that it finished. Only two of those five change between a CSV file and a JSON file.
Written directly, each job is a whole class of its own:
class CsvImportJob { void run(String source) { // read lines, parse, validate, save, report } } class JsonImportJob {
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%