September 2019
Intermediate to advanced
816 pages
18h 47m
English
The classic Strategy pattern is pretty straightforward. It consists of an interface that represents a family of algorithms (strategies) and several implementations of this interface (each implementation is a strategy).
For example, the following interface unifies the strategies for removing characters from the given string:
public interface RemoveStrategy { String execute(String s);}
First, we will define a strategy for removing numeric values from a string:
public class NumberRemover implements RemoveStrategy { @Override public String execute(String s) { return s.replaceAll("\\d", ""); }}
Then, we will define a strategy for removing white spaces from a string:
public class WhitespacesRemover implements ...