From the course: C++ Design Patterns: Behavioral
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Creating strategies - C++ Tutorial
From the course: C++ Design Patterns: Behavioral
Creating strategies
- [Narrator] All right, so now that we've learned the basics of the strategy pattern, let's take a look at an example of what it might look like in code. Now previously, we discussed the example of using the strategy pattern to choose between different sorting algorithms and that's absolutely possible to implement. But for our example here, we're going to do something just a little bit simpler. We're going to use the strategy pattern to allow us to specify different greetings for people in our program. So let me show you what I mean by that. If you look at the starter code for this video, which we have here, and you can find it in the exercise files, you'll see the situation that the strategy pattern is meant to help us with. So specifically we have this person interface with a single greet method. And then what we've had to do is define a new subclass of this interface for each different person that greets…
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
-
-
-
-
-
The Interpreter pattern2m 57s
-
(Locked)
Implementing the Interpreter pattern6m 17s
-
(Locked)
Applying the Interpreter pattern5m 1s
-
(Locked)
The State pattern3m 2s
-
(Locked)
Implementing the State pattern5m 2s
-
(Locked)
Applying the State pattern4m 48s
-
(Locked)
The Strategy pattern2m 37s
-
(Locked)
Creating strategies2m 45s
-
(Locked)
Rewriting classes to use strategies3m 51s
-
(Locked)
The Template Method pattern4m 9s
-
(Locked)
Creating template methods4m 33s
-
(Locked)
Modifying templates using subclasses4m 27s
-
(Locked)
The Visitor pattern2m 57s
-
(Locked)
Implementing visitors4m 55s
-
(Locked)
Allowing classes to accept visitors3m 59s
-
(Locked)
Project: Create a greeting-card generator program10m 10s
-
(Locked)
Challenge: Modifying the card generator1m 49s
-
(Locked)
Solution: Modifying the card generator3m 8s
-
-
-