Abstract step or hook? One question decides it
transcript
You're writing a template method. Every step has to be one of three kinds. Fixed, abstract, or a hook. How do you choose?
Ask one question. Does every subclass have something to say? If yes, the step is abstract. A subclass that forgets it is an error. If only some do, it's a hook, with a default that does nothing. If nobody does, it's fixed, and the base class owns it.
Every format writes a row, so row is abstract. But only the PDF has pages. So the page mark is a hook. CSV and Markdown never mention it. The PDF overrides it, with a mark before every second row. Two pages, from four rows.
Make a hook abstract, and every format writes an empty method. Make a real step a hook, and a new format can forget it. Then it quietly produces a file with no rows. No error, no warning.
Everyone? Abstract. Only some? A hook.
Full breakdown in the lecture.