Refactoring: Replacing Enums with the Strategy Pattern(jeremyjarrell.com)

submitted by jeremyjarrelljeremyjarrell(2685) 4 years, 3 months ago

Here's a simple way to remove all of those ugly switch statements and enums and to buy yourself a little more flexibility and testability as an added bonus!

2 comments |category: |Views: 171

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by powerrushpowerrush(3873) 4 years, 3 months ago 0

Good intro to the Strategy Pattern

Reply

posted by johnvbrennanjohnvbrennan(0) 4 years, 3 months ago 0

This is a very good article. The example is simple to understand and yet also shows off the power available when utilising interfaces. I use enums a lot in my code and for most things they are great. I find they make code more readable but then you hit a scenario where you you have to extend an enum and there's a lot of additional work that comes with that.

John

Reply

information Login or create an account to comment on this story