From the course: JavaScript: Patterns
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Strategy pattern - JavaScript Tutorial
From the course: JavaScript: Patterns
Strategy pattern
- [Instructor] The strategy pattern is basically a way to encapsulate different algorithms or functions and then at runtime practically use the same code to run different scenarios. And we've used this approach in some of the code we've written thus far. So let me show you. So basically if you go into the Exercise Files, and either you use 02_03 or the actual files for this video, so 04_06, it's the same thing. So let's go ahead and use that. So I'm going to drag and drop this inside of Visual Studio Code. And you probably recognize this pattern that we've done in video 02_03. So we created a class car with a constructor with doors, engine, and color as arguments, which we prepped with the constructor here. And then we've extended that with the SUV. And then, again, we added the doors, engine, color and then add this wheels of the number of wheels for a SUV. But the strategy pattern is happening right here. So…
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)
What are behavioral patterns?1m 4s
-
(Locked)
Observer pattern2m 36s
-
(Locked)
State pattern3m 6s
-
(Locked)
Chain of responsibility1m 30s
-
(Locked)
Iterator pattern3m 44s
-
(Locked)
Strategy pattern1m 36s
-
(Locked)
Memento pattern53s
-
(Locked)
Mediator pattern1m 32s
-
(Locked)
Command pattern2m 24s
-
(Locked)
-