The Strategy pattern is easily one of my favorite design patterns. It allows you to add functionality to an object on the fly during program run time. A great example use case for this design pattern is video games such as one of my all time favorites — Old School Runescape. In this game you could add range to your attack by equipping a bow, change your damage type to magic with a staff and runes, or gain a special attack with a weapon such as the granite maul!

In this article, we will be examining real world examples, UML+Sequence diagram and implementation in Go for the Strategy pattern. The code will be based around being able to equip different weapons to a character in order to change their attack capabilities.

Let’s get started!

#golang #programming #design-pattern #go #developer

The Strategy Pattern In Go
3.60 GEEK