Link Details

Link 686289 thumbnail
User 355617 avatar

By piccoloprincipe
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
  • 2282
  • 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)

    Apache Hadoop
    Written by: Piotr Krewski
    Featured Refcardz: Top Refcardz:
    1. Play
    2. Akka
    3. Design Patterns
    4. OO JS
    5. Cont. Delivery
    1. Play
    2. Java Performance
    3. Akka
    4. REST
    5. Java