Pick the fix
Users export a report as PDF, CSV or JSON, chosen at runtime, and more formats are coming. Which pattern?
Hint 1 of 1
Interchangeable algorithms behind one interface.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Strategy: an Exporter protocol with one implementation per format
Correct. New formats are new types, and callers don't change.
Why not the others?
- B A switch on the format in every place that exports. Each new format means editing every switch.
- C Subclass the report screen per format. The format is behaviour, not a kind of screen.
- D Command objects in an undo queue. Commands help with undo and queues, not choosing algorithms.