This design pattern allows you to encapsulate action inside an object to be executed sometime later.
Furthermore, if we can execute one action later on, why not execute many? Why not schedule exactly when to execute?
That's exactly what we need to do in our CatsCraft 2: Revenge of the Dogs game now. Dave, a new developer that we've hired lately, was working hard the whole weekend, while no one was allowed to bother him. He implemented the following abstract methods for our furry soldiers:
class Soldier(...)... {
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
}
}
He probably even used the Bridge design pattern from the previous chapter to do that.
The problem we need to solve now is that...