Strategy
The goal of the Strategy design pattern is to allow an object to alter its behavior at runtime.
Let's recall the platformer game we were designing in Chapter 3, Understanding Structural Patterns, while discussing the Facade design pattern.
Canary Michael, who acts as a game designer in our small indie game development company, came up with a great idea. What if we were to give our hero an arsenal of weapons to protect us from those horrible carnivorous snails?
Weapons all shoot projectiles (you don't want to get too close to those dangerous snails) in the direction our hero is facing:
enum class Direction { LEFT, RIGHT }
All projectiles should have a pair of coordinates (our game is 2D, remember?) and a direction:
data class Projectile(private var x: Int, private var y: Int, ...