Created
November 8, 2023 15:31
-
-
Save trikitrok/27397b1c8ee543157365225579ea252b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// As a direct chain of calls | |
class FlightBooking { | |
constructor(plane) { | |
this.plane = plane; | |
} | |
// ... | |
isSeatAvailable(rowNumber, seat) { | |
return this.plane.getRows()[rowNumber - 1].isAvailable(seat); | |
} | |
} | |
// Chaining calls through intermediate results | |
class FlightBooking { | |
constructor(plane) { | |
this.plane = plane; | |
} | |
// ... | |
isSeatAvailable(rowNumber, seat) { | |
let rows = this.plane.getRows(); | |
const row = rows[rowNumber - 1]; | |
return row.isAvailable(seat); | |
} | |
} | |
//---------------------------------------------------------------------------- | |
//---------------------------------------------------------------------------- | |
class FlightBooking { | |
constructor(plane) { | |
this.plane = plane; | |
} | |
// ... | |
isSeatAvailable(rowNumber, seat) { | |
return this.plane.hasAvailableSeatAt(rowNumber, seat); | |
} | |
} | |
class Plane { | |
constructor(rows) { | |
this.rows = rows; | |
} | |
// ... | |
hasAvailableSeatAt(rowNumber, seat): boolean { | |
return this.rows.isAvailable(rowNumber, seat); | |
} | |
} | |
class Rows { | |
constructor(rows) { | |
this.rows = rows; | |
} | |
// ... | |
isAvailable(rowNumber, seat) { | |
const row = this.rows[rowNumber - 1]; | |
return row.isAvailable(seat); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment