Exercise: Interface Segregation
This exercise puts the Interface Segregation Principle into code. You will define three focused interfaces and two device classes, then drive them with a command sequence.
Scenario
An office-device registry manages two kinds of hardware: a simple printer that can only print, and an all-in-one device that can print, scan, and fax. The registry receives a sequence of commands and returns one output line per command.
Commands
The program reads a list of commands, one per line, and prints one line of output per command.
| Command | Behavior | Output |
|---|---|---|
["add", type, name] | Add a device; type is simple or allinone | "Added <name>", or "Unknown type: <type>" |
["print", name] | Print on the named device | "<name> printed", or "<name> not found" |
["scan", name] | Scan on the named device | "<name> scanned" for all-in-one, "<name> cannot scan" for simple, or "<name> not found" |
["fax", name] | Fax on the named device | "<name> faxed" for all-in-one, "<name> cannot fax" for simple, or "<name> not found" |
7 add simple Laser add allinone Xerox print Laser scan Laser fax Xerox scan Xerox print Ghost
Added Laser Added Xerox Laser printed Laser cannot scan Xerox faxed Xerox scanned Ghost not found
Your task
Create SimplePrinter (implements Printer) and AllInOne (implements Printer, Scanner, and Fax) so each command produces the output above. The starter marks where to add the classes with a TODO comment and shows the exact method signatures and return values to implement.