Skip to content

Latest commit

 

History

History
45 lines (41 loc) · 940 Bytes

function13.md

File metadata and controls

45 lines (41 loc) · 940 Bytes

避免条件

Bad logo

	class Airplane {
	  // ...
	  getCruisingAltitude() {
	    switch (this.type) {
	      case "777":
	        return this.getMaxAltitude() - this.getPassengerCount();
	      case "Air Force One":
	        return this.getMaxAltitude();
	      case "Cessna":
	        return this.getMaxAltitude() - this.getFuelExpenditure();
	    }
	  }
	}

Good logo

	class Airplane {
	  // ...
	}
	
	class Boeing777 extends Airplane {
	  // ...
	  getCruisingAltitude() {
	    return this.getMaxAltitude() - this.getPassengerCount();
	  }
	}
	
	class AirForceOne extends Airplane {
	  // ...
	  getCruisingAltitude() {
	    return this.getMaxAltitude();
	  }
	}
	
	class Cessna extends Airplane {
	  // ...
	  getCruisingAltitude() {
	    return this.getMaxAltitude() - this.getFuelExpenditure();
	  }
	}