June 2018
Intermediate to advanced
310 pages
6h 32m
English
While not directly related, one of the advantages of the Command design pattern is the ability to undo commands. What if we wanted to support such a functionality?
Undoing is usually very tricky, because it involves one of the following:
In our case, the opposite of the command move from (0,0) to (0, 20) would be move from wherever you're now to (0,0). This could be achieved by storing a pair of commands:
private val commands = mutableListOf<Pair<Command, Command>>()
You can also add pairs of commands:
fun appendMove(x: Int, y: Int) ...
Read now
Unlock full access