class Gear {
readonly cog: number;
readonly chainRing: number;
readonly wheel: Wheel;
constructor(cog: number, chainRing: number, wheel: Wheel) {
this.cog = cog;
this.chainRing = chainRing;
this.wheel = wheel;
}
// 새로 추가된 함수
gear_inches() {
// 타이어는 바퀴테를 가싸고 있어서, 지름 계산시 타이어 높이에 2를 곱함
return this.ratio * this.wheel.diameter();
}
}
Gear.new(52, 11, Wheel.new(26, 1.6)).gear_inches();
class Gear {
readonly cog: number;
readonly chainRing: number;
readonly wheel: Wheel;
constructor(cog: number, chainRing: number, wheel: Wheel) {
this.cog = cog;
this.chainRing = chainRing;
this.wheel = wheel;
}
// 새로 추가된 함수
gear_inches() {
// 타이어는 바퀴테를 가싸고 있어서, 지름 계산시 타이어 높이에 2를 곱함
return this.ratio * this.wheel.diameter();
}
}
class Gear {
readonly cog: number;
readonly chainRing: number;
readonly wheel: Wheel;
constructor(cog: number, chainRing: number, wheel: Wheel) {
this.cog = cog;
this.chainRing = chainRing;
this.wheel = wheel;
}
// 새로 추가된 함수
gear_inches() {
// 타이어는 바퀴테를 가싸고 있어서, 지름 계산시 타이어 높이에 2를 곱함
return this.ratio * this.wheel.diameter();
}
wheel() {
return this.wheel || Wheel.new(this.rim, this.tire);
}
}
gear_inches() {
// 무시무시한 수학 공식 몇 줄
foo = this.ratio * this.wheel.diameter();
// 무시무시한 수학 공식 몇 줄
}
gear_inches() {
// 무시무시한 수학 공식 몇 줄
foo = this.ratio * this.diameter();
// 무시무시한 수학 공식 몇 줄
}
// 클래스 내부에 메서드 속에 캡슐화
diameter() {
return wheel.diameter();
}
// Gear가 외부 프레임워크의 한 부분일 때
// Gear/index.js
class Gear {
readonly cog: number;
readonly chainRing: number;
readonly wheel: Wheel;
constructor(cog: number, chainRing: number, wheel: Wheel) {
this.cog = cog;
this.chainRing = chainRing;
this.wheel = wheel;
}
}
// GearWrapper.js
// 외부 인터페이스를 감싸는 모듈을 만들어 변화를 받아들이자.
import Gear from 'Gear';
export gear (arg) {
Gear.new(arg.cog, arg.chainRing, arg.wheel)
}
// myCode.js
import * as GearWrapper from './GearWrapper';
GearWrapper.gear({
chainring: 15,
cog: 11,
wheel: new Wheel(26, 1.6).gear_inches()
})