-
Book Overview & Buying
-
Table Of Contents
Practical C# Projects with .NET
By :
One of my favorite design patterns is the Strategy pattern. The strategy pattern essentially lets you take some sort of logic and wrap it into an object. This strategy object can then be executed using whatever additional external pieces of information are needed.
When you use Strategy objects like this, you're effectively taking behavior logic in your application and pulling it out of a method and into its own dedicated Strategy class. On the surface, this might not sound too helpful, but in practice, this lets you take a lot of disparate concerns that might otherwise have lived in a long and complex method and move those concerns into their own dedicated objects. This simplifies your original logic significantly, makes it easier to test those smaller strategy objects, and makes your system more flexible when you need to add more behaviors in the future – or find new uses for existing behaviors.