October 2019
Intermediate to advanced
434 pages
11h 54m
English
Let's walk through an example of implementing the Factory pattern to retrieve difficulty settings for a particular game. What we want to achieve is something like this:
val settings = DifficultySettings.getSettings(GameDifficulty.HARD)println("Difficulty Settings = ${settings.label}")
Our goal is to use our Factory method, in this case getSettings(), to retrieve an instance of some settings type and be able to work with that type without needing to understand how that type is actually instantiated. To implement this, perform the following steps:
enum class GameDifficulty { EASY, ...
Read now
Unlock full access