# StatePattern Canvas example

**URL:** <https://forum.codewithmosh.com/t/statepattern-canvas-example/3081>\
**Category:** Design Patterns\
**Created:** [March 1, 2021, 3:40am UTC](https://forum.codewithmosh.com/t/statepattern-canvas-example/3081 "2021-03-01T03:40:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kannans89](https://avatars.discourse-cdn.com/v4/letter/k/b2d939/32.png) [@Kannans89](https://forum.codewithmosh.com/u/Kannans89)\
**Post date:** [March 1, 2021, 3:40am UTC](https://forum.codewithmosh.com/t/statepattern-canvas-example/3081/1 "2021-03-01T03:40:28Z")

</div>

Hello , I have a doubt to clarify the Canvas and the tools example given by Mosh looks like strategy pattern ? Correct me if I am wrong. There is no state transitions happening in the pattern and the states are set from outside . So is this usecase for strategy pattern ?

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [August 10, 2022, 11:20pm UTC](https://forum.codewithmosh.com/t/statepattern-canvas-example/3081/2 "2022-08-10T23:20:50Z")

</div>

If you are basically wondering about the difference between the two patterns, the first few answers over at StackOverflow to this question are very useful: [What is the difference between Strategy design pattern and State design pattern? - Stack Overflow](https://stackoverflow.com/questions/1658192/what-is-the-difference-between-strategy-design-pattern-and-state-design-pattern)

If you are wondering specifically about the Canvas / Tools example - I do believe it falls more under the State pattern since it is about changing the behavior of the canvas based on the selected tool. Implementation wise they look very similar.

In a Strategy pattern, we would mostly be trying to do the same “goal”, but selecting between different strategies to achieve that goal. A common example is sorting since there are tradeoffs between sorting algorithms and it could be wise to select between those tradeoffs even though your “goal” is consistent: sort the supplied data. So the “strategies” would be things like “quicksort” or “mergesort” or “bubblesort”.

I hope that helps anyone else who ends up wondering the same question.
