Strategy pattern
A strategy design pattern is a behavioral pattern that is used to represent a family of algorithms. An algorithm within such a family is represented as a strategy object. The pattern enables easy switching between different strategies (algorithms) of a particular family. This is generally useful when you want to switch to a different strategy at runtime. We will revisit this definition towards the end of the discussion on strategy pattern.
Strategy scenario – The jump feature
There is a high priority feature request. Rather, it is a complaint. The users just hate the movement restriction imposed by the fence. Now even Sir Foo has joined the protest... |
Rather than removing the fence from the scenario, how about a new feature that enables units to jump over the fence or any similar obstacle? |
You have introduced a new method, jump()
, in the superclass AbstractGameUnit
. All the classes inherit this method, as shown in the following class diagram:
The fence no longer prevents...