clean-code-javascript icon indicating copy to clipboard operation
clean-code-javascript copied to clipboard

#Avoid conditionals# Is that means redux sucks?

Open eleven-huang opened this issue 4 years ago • 0 comments

#Avoid conditionals#

` BAD

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:

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(); } } `

So redux is a bad smell?

eleven-huang avatar Aug 12 '20 15:08 eleven-huang