Are these 3 Examples of the Strategy Pattern?

I want to be sure I understand things right, so…

  1. A MonoBehaviour called SkillDisplayer that takes an instance of something that inherits ISkill. What the former does is display the icon and name of the latter somewhere in the UI. The use of the Strategy Pattern here would be swapping out said ISkill instance for another one, making SkillDisplayer change the icon and name displayed to fit the new instance it represents.

  2. A SkillExecutor MonoBehaviour that also takes an instance of ISkill, but it does things like apply damage or healing based on what’s in the latter. This is another class that lets you swap out its ISkill instance so it acts in line with it.

  3. Unity’s built-in Animator component letting you swap out its runtime animator controller so that a character executes different animations at different times.

  1. Yes
  2. Yes
  3. Yes
1 Like

What he said. All three are examples of the Strategy pattern.

For a practical application of the Strategy pattern in action, our Shops and Abilities course utilizes the Strategy pattern to allow Abilities in an RPG game to be created within the Editor using simple building blocks of targeting strategies, filter strategies, and effect strategies.

2 Likes

Thank you very much, guys! ^^ I probably will get to that Shops and Abilities course at some point

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms