Vloží zameniteľný algoritmus do objektu, ktorý sa dá podsunúť za behu.
class Route { find(from, to) { throw new Error('abstraktná metóda'); }} class ByCar extends Route { find(from, to) { // along roads, shortest time }} class OnFoot extends Route { find(from, to) { // through parks and stairs too }} class Navigation { #route; // The client supplies the strategy. Navigation never swaps it itself. setRoute(route) { this.#route = route; } find(from, to) { return this.#route.find(from, to); }} const navigation = new Navigation(); navigation.setRoute(new ByCar());navigation.find(home, work); navigation.setRoute(new OnFoot());navigation.find(home, work);