Grokking Design Patterns for Engineers and Managers
0% completed
Strategy Pattern
The Strategy Pattern swaps an algorithm at run time behind one interface, instead of branching on a type inside the caller.
One job has several ways to do it. Retrying a failed request can mean not retrying at all, waiting a fixed delay, or backing off exponentially. Which one is right depends on the environment, the endpoint, and sometimes the customer.
Written directly, it becomes a branch inside the class that makes the call:
if (policy == NONE) { /* give up */ } else if (policy == FIXED) { /* wait 100ms and try again */ }
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%