Link Details

Link 686289 thumbnail
User 355617 avatar

By piccoloprincipe
via css.dzone.com
Published: Oct 24 2011 / 09:16

In the scenario of today, an if chooses to execute different behavior depending on the type of an object. We should define "type" very looosely; for example, it may be the class of the object or one of the interfaces it implements (instanceof); the value of one of the object's fields (usually enumerative). Each of these discriminants has the power to be used in dozens of identical conditionals throughout the codebase. We can replace easily this kind of conditionals with polymorphism: we move the relevant logic in the object whose type is queried.
  • 5
  • 0
  • 2248
  • 220

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (5)



Voters Against This Link (0)



    Java Performance Optimization
    Written by: Pierre-Hugues Charbonneau
    Featured Refcardz: Top Refcardz:
    1. Design Patterns
    2. OO JS
    3. Cont. Delivery
    4. Java EE7
    5. HTML5 Mobile
    1. Node.js
    2. Debugging JavaScript
    3. OO JS
    4. JSON
    5. Ajax