01The problem
Printing is where a POS meets the real world. A receipt goes to the counter, an order ticket goes to the kitchen, labels and reports go wherever they're needed. Each merchant has different printers: a Bluetooth printer on the counter, a networked one in the kitchen, the printer built into a Sunmi device. Each vendor has its own SDK or none at all.
Supporting a new printer used to mean adding another branch to code that already had many.
02The decision
One contract that every printer implements, whatever the vendor or transport. The rest of the app talks only to that contract. It doesn't know or care whether the bytes go over Bluetooth, USB or a socket.
// Illustrative shape, not the production interface.
interface Printer {
suspend fun connect(): Result<Unit>
suspend fun isConnected(): Boolean
suspend fun print(job: PrintJob): Result<Unit>
fun disconnect()
}
// A job is an ordered list of operations: text, image, QR, cut, cash drawer...
class PrintJob(val operations: List<PrintOperation>)
On top of the contract:
- Jobs and operations. What to print is described as a job made of operations, separate from how a given printer carries them out. One execution path handles receipt, checker, label and report printing, with race-condition handling built in.
- Routing. Merchants decide which printer gets which document, and route items to printers by product group.
- Discovery and persistence. A printer discovery screen, and a persistent identifier for USB printers so the app reconnects to the same device.
03Result
Supporting new hardware became a matter of implementing an interface rather than adding a branch.
Sunmi's built-in printer, generic USB printers and generic network printers were each added that way, and so were features like image printing, receipt logos and printed QRIS codes. The same generic printer SDK was then adopted by the kiosk, so both products share one printing stack.