Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replacing Conditionals with Polymorphism

 
Cory Hartford
Ranch Hand
Posts: 85
Eclipse IDE Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know for the vets this has been discussed to death, but for the newer people I wanted to share. I set out yesterday to replace an if statement based on a boolean flag; I was convinced there was a better way.. And there was, but it took some mind twisting to get there. I learned a lot of really really important programing Philosophy that I'd sort of been foggy on previously. Granted it might have been overkill but I wanted understand the concept so I was ok with the simplistic usage.
The last code block in this first post gives a really great example of a very simplistic implementation of the idea. More importantly, I watched the Google Clean Code talk video (which is linked in the post right above the code I am referencing) and that really blew my mind. I had to watch it several times understand the specifics. Definitely worth the effort though.

Hope this is helpful to people.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a tip...you say "the last code block in this post". the problem I see is that people can continually add new answers to that page, thus putting in new code blocks at the end, and depending on how people vote, entire sections can be moved around.

Can you be more specific which block of code you are referring to?
 
Cory Hartford
Ranch Hand
Posts: 85
Eclipse IDE Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fred. What I found most helpful and what I was referring to in the post is the section of the linked post in between the heading marked "Your Thoughts below this line" and the Author's portrait.

Although it linked in the paragraph in that section, here is the link for the Google Clean Code talk.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies...i think I missed the word 'first' in the "in this first post" when I read it initially.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic