Last active
September 20, 2018 09:03
-
-
Save chul-hyun/e357f0bb2288db502b71e3bbb1dd7f8b to your computer and use it in GitHub Desktop.
Chapter3
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
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.wheel.diameter; | |
} | |
private get wheel() { | |
if (this._wheel === undefined) { | |
this._wheel = new Wheel(this.rim, this.tire); | |
} | |
return this._wheel; | |
} | |
} | |
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