A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://refactoring.com/catalog/replaceConditionalWithPolymorphism.html below:

Replace Conditional with Polymorphism

Replace Conditional with Polymorphism

switch (bird.type) {
  case 'EuropeanSwallow':
    return “average”;
  case 'AfricanSwallow':
    return (bird.numberOfCoconuts > 2) ? “tired” : “average”;
  case 'NorwegianBlueParrot':
    return (bird.voltage > 100) ? “scorched” : “beautiful”;
  default:
    return “unknown”;

image/svg+xml

class EuropeanSwallow {
  get plumage() {
    return “average”;
  }
class AfricanSwallow {
  get plumage() {
     return (this.numberOfCoconuts > 2) ? “tired” : “average”;
  }
class NorwegianBlueParrot {
  get plumage() {
     return (this.voltage > 100) ? “scorched” : “beautiful”;
  }

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3