From the course: Node.js: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implementing strategies

Implementing strategies - Node.js Tutorial

From the course: Node.js: Design Patterns

Start my 1-month free trial

Implementing strategies

- [Narrator] In the last lesson we introduced the strategy design pattern and discovered how we could work with it. In this lesson we're going to implement the pattern by creating several log strategies in a single class. So, the first thing we want to do is encapsulate all of our strategies, all of our algorithms in a single class in a single file. So I'm going to go over here to the start folder. We are in the exercise files for chapter four, chapter four lesson 11 and within that start folder we have the index code that we changed to use the change strategy on line seven as well as the config.json file where we are able to set the strategy before the application gets started. So let's go ahead and add another file to this called log strategy.js and what we want to do in this file is create a class that we call log strategy and we're never going to instantiate any objects with this class. What we're going to do is just save several static methods to this class and each static method…

Contents