Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created February 3, 2023 20:10
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/af1db39f81bc73038dea19abb626c9d8 to your computer and use it in GitHub Desktop.
Save trikitrok/af1db39f81bc73038dea19abb626c9d8 to your computer and use it in GitHub Desktop.
// As a direct chain of calls
class FlightBooking {
private plane: Plane;
constructor(plane: Plane) {
this.plane = plane;
}
// ...
isSeatAvailable(rowNumber: number, seat: string): boolean {
return this.plane.getRows()[rowNumber - 1].isAvailable(seat);
}
}
// Chaining calls through intermediate results
class FlightBooking {
private plane: Plane;
constructor(plane: Plane) {
this.plane = plane;
}
// ...
isSeatAvailable(rowNumber: number, seat: string): boolean {
let rows = this.plane.getRows();
const row = rows[rowNumber - 1];
return row.isAvailable(seat);
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class FlightBooking {
private plane: Plane;
constructor(plane: Plane) {
this.plane = plane;
}
// ...
isSeatAvailable(rowNumber: number, seat: string): boolean {
return this.plane.hasAvailableSeatAt(rowNumber, seat);
}
}
class Plane {
private rows: Rows;
constructor(rows: Rows) {
this.rows = rows;
}
// ...
hasAvailableSeatAt(rowNumber: number, seat: string): boolean {
return this.rows.isAvailable(rowNumber, seat);
}
}
class Rows {
private readonly rows: Row[];
constructor(rows: Row[]) {
this.rows = rows;
}
// ...
isAvailable(rowNumber: number, seat: string): boolean {
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