• Albert Bennett

Design Patterns: Strategy

Updated: Jul 12, 2021

Here is the link to the GitHub repo :)

Feel free to like, comment and share this post.

In this post, I'll be going through the Strategy pattern. What is it used for and how does it work.

First of, this pattern is used for when you want to change the behaviour of an object without extending it. This is done through the use of a context object that holds a reference to an implementation of IStrategy. Here is a diagram to explain what it is:

Context: This class is used to access and call the DoSomething method of our strategy objects.

StrategyA/ StrategyB: Theses classes are children of the IStrategy interface and where the core functionality is held.

As you can see from the image below, when we change the IStrategy object the behavior of the Context object changes.

I Hop that this helps you to understand the Strategy pattern better. Until next time... ᕕ( ᐛ )ᕗ

<< More Design Patterns

5 views0 comments

Recent Posts

See All