From the course: Programming Foundations: Design Patterns

Unlock the full course today

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

Solution: The Strategy pattern

Solution: The Strategy pattern

From the course: Programming Foundations: Design Patterns

Start my 1-month free trial

Solution: The Strategy pattern

(energetic music) - [Narrator] Here's our solution to the challenge. We've pulled out the different ways of sharing into a separate family of classes that implement sharing by texting, sharing by email, and sharing on social media. This is our family of algorithms. We've also added a property to the PhoneCameraApp superclass that will be composed with a strategy that the user selects. Now when the share method is called, the super class is going to delegate sharing to the user's preferred share strategy. So this design allows us to more easily add, change, and remove sharing strategies without have to modify any code in the camera app or any code in the concrete camera app classes.

Contents