Skip to content

Instantly share code, notes, and snippets.

@chul-hyun
Created September 20, 2018 09:03
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 chul-hyun/d85a833e3f88ce41159fa4fa429776f5 to your computer and use it in GitHub Desktop.
Save chul-hyun/d85a833e3f88ce41159fa4fa429776f5 to your computer and use it in GitHub Desktop.
Chapter3
class Gear {
private _wheel: Wheel;
constructor(
readonly chainring: number,
readonly cog: number,
readonly rim: number,
readonly tire: number
) {}
get ratio() {
return this.chainring / this.cog;
}
get gearInches() {
return this.ratio * this.diameter;
}
private get wheel() {
if (this._wheel === undefined) {
this._wheel = new Wheel(this.rim, this.tire);
}
return this._wheel;
}
private get diameter() {
return this.wheel.diameter
}
}
class Wheel {
constructor(readonly rim: number, readonly tire: number) {}
get diameter() {
return this.rim * (this.tire * 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment