Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created November 8, 2023 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trikitrok/27397b1c8ee543157365225579ea252b to your computer and use it in GitHub Desktop.
Save trikitrok/27397b1c8ee543157365225579ea252b to your computer and use it in GitHub Desktop.
// 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