• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replacing Conditionals with Polymorphism

 
Ranch Hand
Posts: 85
Mac Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic