Skip to content

Instantly share code, notes, and snippets.

Created March 23, 2022 23:51
What would you like to do?


Design Patterns that will be covered in this article:

  • Strategy


This design pattern defines a family of interchangeable objects that can be set or switched at runtime. Also, Strategy is categorized under Behavioral patterns because the Strategy pattern is ultimately about 1 object using another to do something.

This pattern has 3 parts in-total:

  • The object using a strategy (typically, a view controller in an iOS app)
  • The Strategy Protocol
    • This protocol defines methods that every strategy must implement
  • The strategies are objects that conform to the Strategy Protocol

When Should You Use It?

  1. Use the strategy pattern when you have 2 or more different interchangeable behaviors
  2. Unlike Delegation, the strategy pattern defines a family of objects
  3. Strategies are intended to be easily changeable at runtime whereas Delegation are often fixed at runtime



Screen Shot 2022-03-23 at 7.42.29 PM.png


Screen Shot 2022-03-23 at 7.43.10 PM.png


Screen Shot 2022-03-23 at 7.43.55 PM.png


Screen Shot 2022-03-23 at 7.44.38 PM.png


Screen Shot 2022-03-23 at 7.44.59 PM.png


Screen Shot 2022-03-23 at 7.45.34 PM.png


Screen Shot 2022-03-23 at 7.46.36 PM.png

Finished Project

Screen Shot 2022-03-23 at 7.49.55 PM.png Screen Shot 2022-03-23 at 7.50.10 PM.png

What Should You be Careful About?

  • Be careful about pre-optimizing and overusing this pattern.
  • If a behavior won't ever change, it's perfectly okay to code it in a controller / object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment