Created
February 3, 2023 20:10
-
-
Save trikitrok/af1db39f81bc73038dea19abb626c9d8 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 { | |
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