From the course: Node.js: Design Patterns
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
The Strategy pattern - Node.js Tutorial
From the course: Node.js: Design Patterns
The Strategy pattern
- [Instructor] One of the most powerful and most dynamic design patterns is the strategy. The strategy pattern let's you create multiple algorithms for a specific task and then dynamically decide upon which algorithm to use at run time. An example of a common place that the strategy pattern is used is with payment processing. We could build a shopping cart and checkout process that only let's users make purchases via a credit card. In this case the checkout process would always use the same algorithm, the credit card payment. We could also modify the checkout process to implement a strategy. This means that we decouple how to handle payments from the process itself. Now we can add different strategies for handling payments. We could add a credit card strategy and a PayPal strategy and then let the user decide which one to use dynamically at run time. The cool thing about strategies is that we can add new strategies as the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Chain of responsibility4m 42s
-
(Locked)
Implementing the storage class6m 22s
-
(Locked)
The Command pattern4m 47s
-
(Locked)
Implementing commands4m 59s
-
(Locked)
Improving the conductor6m 38s
-
(Locked)
The Iterator pattern4m 5s
-
(Locked)
Implementing iterators4m 59s
-
(Locked)
The Observer pattern4m 19s
-
(Locked)
Implementing observers2m 48s
-
(Locked)
The Strategy pattern4m 25s
-
(Locked)
Implementing strategies9m 36s
-
(Locked)
-