Command
This design pattern allows you to encapsulate actions inside an object to be executed sometime later. Furthermore, if we can execute one action later, we could also execute many, or even schedule exactly when to execute them.
Let's go back to our Stormtrooper
management system from Chapter 3, Understanding Structural Patterns. Here's an example of implementing the attack
and move
functions from before:
class Stormtrooper(...) { fun attack(x: Long, y: Long) { println("Attacking ($x, $y)") // Actual code here } fun move(x: Long, y: Long) { println("Moving to ($x, $y)") // Actual code here } }
We could even use the Bridge design pattern from the...