[TypeScript] ๐Ÿณ 3.2 ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ

18456 ๋‹จ์–ด typescripttypescript

๐Ÿณ 3.2 ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ

์ƒ์„ฑ์ž๋ฅผ ํฌํ•จ์‹œํ‚จ ์ปค์Šคํ…€ ํƒ€์ž…์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ผ๋ฐ˜ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉ / ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉํ•จ

๐ŸŒ 3.2.1 ์ธํ„ฐํŽ˜์ด์Šค ๊ฐ•์ œ

์†์„ฑ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ฉ”์„œ๋“œ์„ ์–ธ๋„ ํฌํ•จํ•  ์ˆ˜ ์žˆ๋‹ค. ( โ— ๋ฉ”์„œ๋“œ ๊ตฌํ˜„์€ ์•„๋‹˜. )

implementsํ‚ค์›Œ๋“œ์™€ ์ธํ„ฐํŽ˜์ด์Šค ์ด๋ฆ„์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ.

=> ๋ฉ”์„œ๋“œ ์‹œ๊ทธ๋‹ˆ์ฒ˜๋งŒ์„ ํฌํ•จํ•˜์ง€๋งŒ, ํด๋ž˜์Šค๋Š” ๋ฉ”์„œ๋“œ ๊ตฌํ˜„์ด ํฌํ•จ๋  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ‘‰ Example

// 3_13.ts
interface MotorVeghicle3_13{
  startEngine(): boolean;
  stopEngine(): boolean;
  brake(): boolean;
  accelate(speed: number);
  hank(HowLong: number): void;
}

๋ฉ”์„œ๋“œ ๊ตฌํ˜„์€ ์—†์Œ.

์œ„ ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ํด๋ž˜์Šค Car๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

class Car3_13 implements MotorVehicle3_13{

}

์ด ๊ฒฝ์šฐ ํด๋ž˜์Šค ์„ ์–ธ์€ ์ปดํŒŒ์ผ๋˜์ง€ ์•Š์•„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒ.

์ธํ„ฐํŽ˜์ด์Šค๋กœ ํด๋ž˜์Šค๋ฅผ ์„ ์–ธํ•  ๋•Œ, ์ธํ„ฐํŽ˜์ด์Šค ๋‚ด ๊ฐ ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผํ•จ.

// 3_14.ts
interface MotorVehicle3_14{
  startEngine(): boolean;
  stopEngine(): boolean;
  brake(): boolean;
  accelate(speed: number);
  hank(HowLong: number): void;
}

class Car3_14 implements MotorVehicle3_14{
  startEngine(): boolean{
    return true;
  }
  stopEngine(): boolean{
    return true;
  }
  brake(): boolean{
    return true;
  }
  accelate(speed: number){
    console.log(`Driving faster`);
  }
  hank(HowLong: number): void {
    console.log(`Beep beep yeah!`);
  }
}

const car = new Car3_14();
car.startEngine();

car์˜ ํƒ€์ž…์„ ๋ช…์‹œ์ ์œผ๋กœ ์„ ์–ธํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

const car: Car3_14 = new Car3_14();

์ด ์ฒ˜๋Ÿผ ๋ช…์‹œ์ ์œผ๋กœ ์„ ์–ธ ๊ฐ€๋Šฅ.

const car:MotorVehicle3_14 = new Car3_14();

Carํด๋ž˜์Šค๋Š” ์ปค์Šคํ…€ ํƒ€์ž…์„ ๊ตฌํ˜„ํ•˜๋ฏ€๋กœ ์ƒ์ˆ˜ car์— Motor Vehicleํƒ€์ž… ์„ ์–ธ ๊ฐ€๋Šฅ

๐Ÿ‘‰ ์ฐจ์ด์ 

์œ„ ๋‘๊ฐ€์ง€์˜ ์ฐจ์ด์ ์„ ์•Œ์•„๋ณด์ž.

๋งŒ์•ฝ Car๊ฐ€ 8๊ฐœ์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผํ•œ๋‹ค๊ณ  ํ•˜๋ฉด, Carํƒ€์ž…์ด๋ฉด, ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค๋‚ด 8๊ฐœ๋ฅผ ๋ชจ๋‘ ํ˜ธ์ถœ ๊ฐ€๋Šฅ.
MotorVehicleํƒ€์ž…์ด๋ฉด ์ธ์Šคํ„ด์Šค์— ์„ ์–ธ๋œ ๋ฉ”์„œ๋“œ๋งŒ ํ˜ธ์ถœ ๊ฐ€๋Šฅ

์ด๋ฅผ ์ธํ„ฐํŽ˜์ด์Šค๋Š” ํŠน์ • ๊ทœ์•ฝ์„ ๊ฐ•์ œํ•œ๋‹ค๊ณ  ๋งํ•  ์ˆ˜ ์žˆ๋‹ค.


// 3_15.ts
interface Flyable3_15{
    fly(howHigh: number);
    land();
}

interface Swimmable3_15{
    swim(howFar: number);
}

์•ž์˜ 3๊ฐ€์ง€๋ฅผ ํ•ฉ์ณ๋ณด์ž.

// 3_16.ts
class Car3_16 implements MotorVehicle3_16, Flyable3_16, Swimmable3_16{
	// 3๊ฐœ์˜ ์ธํ„ฐํŽ˜์ด์Šค ๋‚ด ๋ชจ๋“  ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„
}

Car์ „์ฒด์— Flyable๊ณผ Swimmable์„ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•˜๋Š”๊ฑด ์ข‹์€ ๋ฐฉ๋ฒ•์ด ์•„๋‹˜.

์ƒ์†๊ฐœ๋…์„ ์ ์šฉํ•ด Carํด๋ž˜์Šค๋ฅผ ํ™•์žฅํ•˜๊ณ , ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๋ณด์ž.

class SecretServiceCar3_17 extends Car3_17 implements Flyable3_17, Swimmable3_17{
  // flyable๊ณผ swimmable ๋‚ด ๋ชจ๋“  ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„
}

Carํด๋ž˜์Šค๊ฐ€ MotorVehicle ์ธํ„ฐํŽ˜์ด์Šค์— ์ •์˜๋œ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง.

๐ŸŒ 3.2.2 ์ธํ„ฐํŽ˜์ด์Šค ํ™•์žฅ

MotorVehicle์ธํ„ฐํŽ˜์ด์Šค ๋‚ด์˜ ๊ฐ ๋ฉ”์„œ๋“œ๋ฅผ ๋‹ค๋ฅด๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

// 3_18.tsclass SecretServiceCar3_18 implements MotorVehicle3_18, Flyable3_18, Swimmable3_18{  // 3๊ฐ€์ง€ ์ธํ„ฐํŽ˜์ด์Šค ๋‚ด ๋ชจ๋“  ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„}

์ธํ„ฐํŽ˜์ด์Šค ํ™•์žฅ

// 3_19.tsinterface MotorVehicle3_19{  startEngine(): boolean;  stopEngine(): boolean;  brake(): boolean;  accelate(speed: number);  hank(HowLong: number): void;}interface Flyable3_19 extends MotorVehicle3_19{    // ํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฉ”์„œ๋“œ ์‹œ๊ทธ๋‹ˆ์ฒ˜  fly(howHigh: number);  land();}

์ด ํ›„ ํด๋ž˜์Šค ์„ ์–ธ์— implements Flyable ๊ตฌ๋ฌธ์ด ํฌํ•จ๋˜ ์žˆ์œผ๋ฉด MotorVehicle ์ธํ„ฐํŽ˜์ด์Šค์— ์„ ์–ธ๋œ 5๊ฐœ ๋ฉ”์„œ๋“œ์™€ Flyable์˜ ๋‘ ๋ฉ”์„œ๋“œ๋ฅผ ํ•ฉ์นœ ์ด 7๊ฐœ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผํ•จ.

// 3_20.tsclass SecretServiceCar3_20 implements Flyable3_20, Swimmable3_20{  startEngine(): boolean{    return true;  }  stopEngine(): boolean{    return true;  }  brake(): boolean{    return true;  }  accelate(speed: number){    console.log(`Driving faster`);  }  hank(howLong: number): void{    console.log(`Beep Beep!!`)  }  fly(howHigh: number){    console.log(`Flying ${howHigh} feet high`);  }  land(){    console.log(`Landing. Fasten your belts`);  }  swim(howFar: number){    console.log(`Swimming ${howFar} feet`);  }}

๋ฉ”์„œ๋“œ ์‹œ๊ทธ๋‹ˆ์ฒ˜๋ฅผ ํฌํ•จํ•œ ์ธํ„ฐํŽ˜์ด์Šค ์„ ์–ธ์€ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ์„ ๋†’์—ฌ์คŒ.

์ธํ„ฐํŽ˜์ด์Šค๋Š” ๊ฐ ๊ธฐ๋Šฅ์ด ์ž˜ ์ •์˜๋œ ์ง‘ํ•ฉ์œผ๋กœ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ด์šฉํ•ด ๊ตฌ์ฒด์ ์ธ ํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

๐ŸŒ 3.2.3 ์ธํ„ฐํŽ˜์ด์Šค ํ”„๋กœ๊ทธ๋ž˜๋ฐ

๋จผ์ € ์ธํ„ฐํŽ˜์ด์Šค ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ๋ฅผ ๋ณด์ž.

ํ•œ๊ฐ€์ง€ ๋˜๋Š” ๋ชจ๋“  ์ œํ’ˆ ์ •๋ณด๋ฅผ ์ฝ๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค๊ณ  ํ•  ๋•Œ, ๋จผ์ € ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๊ฐ ๊ธฐ๋Šฅ์„ ๋ฐ”๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐ ์ง‘์ค‘ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๐Ÿ‘‰ Example

class Product{  id: number;  description: string;}class ProductService{  getProducts(): Product[]{    // ๋ชจ๋“  products ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ด.    return [];  }  getProductById(id: number): Product{    // id๋ฅผ ์กฐํšŒํ•ด product์˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ด.    return {id: 123, description: 'Good product'};  }}

๊ทธ๋Ÿฌ๊ณ  ๋‚˜์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ProductService ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

const productService = new ProductService();const products = productService.getProducts();

์„œ๋ฒ„๊ฐ€์—†์œผ๋‹ˆ ๋™์ผํ•œ API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” MockProductServiceํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ œํ’ˆ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด ๋ณด์ž.

// 3_22.tsclass MockProductService3_22{	getProducts(): Product3_22[]{    // ํ•˜๋“œ ์ฝ”๋”ฉ๋œ ์ œํ’ˆ ์ •๋ณด๋ฅผ ๋ฐ›๋Š” ์ฝ”๋“œ ์ž‘์„ฑ.    return [];  }  getProductById(id: number): Product3_22{    return {id: 456, description: 'Not a real product'};  }}

MockProductServiceํด๋ž˜์Šค๋Š” ProductService ํด๋ž˜์Šค์™€ ๋™์ผํ•œ ๋‘ ๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธํ–ˆ์ง€๋งŒ, ๋ฐ˜๋Œ€์˜ ๊ฒฝ์šฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

=> ์ด๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด MockProductService ํด๋ž˜์Šค์— ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ฐ•์ œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

implementsํ‚ค์›Œ๋“œ๋กœ ๋‹ค๋ฅธ ํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ž˜์™€ ๊ฐ™์ด MockProductServiceํด๋ž˜์Šค๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•จ.

class MockProductService3_22 implements ProductService{    // ๊ตฌํ˜„}

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋Š” implements ํ‚ค์›Œ๋“œ๋’ค์— ํด๋ž˜์Šค์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๋ฉด ProductService์˜ ๋ชจ๋“  ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ•์ œ๋กœ ๊ตฌํ˜„ํ•˜๋„๋ก ๋งŒ๋“ญ๋‹ˆ๋‹ค. => ์™„๋ฒฝํ•˜๊ฒŒ ๊ตฌํ˜„๋ ๋•Œ๊นŒ์ง€ ์ปดํŒŒ์ผ๋˜์ง€ ์•Š์Œ

โ— ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์€ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ธํ„ฐํŽ˜์ด์Šค์— ์ง‘์ค‘ํ•ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ.

2๊ฐœ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ProductService๋ฅผ ์ž‘์„ฑํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ, ๊ตฌํ˜„์— ๋Œ€ํ•œ ๊ฑฑ์ • ์—†์ด ์ด๋Ÿฌํ•œ ๋ฉ”์„œ๋“œ๋กœ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์‹œ์ž‘ํ•ด์•ผํ•จ.

// 3_23interface Product3_23{ // ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•œ ์ปค์Šคํ…€ ํƒ€์ž… ์„ ์–ธ  id: number;  description: string;}interface IProductService3_23{ // API๋ฅผ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์„ ์–ธ  getProducts(): Product3_23[];  getProductById(id: number):Product3_23;}class ProductService3_23 implements IProductService3_23{  getProducts(): Product3_23[]{    // ์‹ค์ œ ๋ฐ์ดํ„ฐ์—์„œ ์ œํ’ˆ์„ ๋ฐ›์Šต๋‹ˆ๋‹ค.    return [];  }  getProductById(id: number): Product3_23{    // id๋กœ ์ œํ’ˆ์„ ์กฐํšŒํ•จ.    return {id: 123, description: 'Good product'};  }}

API๋ฅผ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์„ ์–ธํ•œ๋‹ค. = ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์— ๋Œ€ํ•ด ์ž์„ธํ•˜๊ฒŒ ๊ตฌํ˜„ํ–ˆ๋‹ค. ๋Š” ์˜๋ฏธ

MockProductService๊ฐ™์€ ์ƒˆ ํด๋ž˜์Šค๋ฅผ ๊ตฌํ˜„ํ•ด์•ผํ•œ๋‹ค๋ฉด?

class MockProductService implements IProductService{  // ๋ฉ”์†Œ๋“œ ๊ตฌํ˜„}

์ปค์Šคํ…€ ํƒ€์ž…์„ ์ดˆ๊ธฐํ™” ํ•  ํ•„์š”๊ฐ€ ์—†์„ ๋•Œ class ๋Œ€์‹  interface ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด JS์ฝ”๋“œ์–‘์ด ์ค„์–ด๋“ฌ

์ธํ„ฐํŽ˜์ด์Šค ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์ข‹์€ ์˜ˆ๋Š” ํŒฉํ† ๋ฆฌํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ.

โ— ํŒฉํ† ๋ฆฌ ํ•จ์ˆ˜๋ž€ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๊ณ  ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜.

// 3_24function getProductService3_24(isProduction: boolean): IProductService3_24{  if( isProduction){    return new ProductService3_10();  }else{    return new MockProductService3_24  }}const productService3_24: IProductService3_24; // ์ธํ„ฐํŽ˜์ด์Šค ํƒ€์ž…์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ƒ์ˆ˜...const isProd = true; // ํ˜„์žฌ ํ”„๋กœ๋•์…˜ ์ƒํƒœ์ž„์„ ๋‚˜ํƒ€๋ƒ„productService3_24 = getProductService3_24(isProd); // productService ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€์ ธ์˜ดconst products3_24[] = productService3_24.getProducts(); // productService ๋‚ด ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœ.

isProd๋Š” true๋กœ ํ•˜๋“œ์ฝ”๋”ฉ๋˜์žˆ์ง€๋งŒ, ์‹ค์ œ ์•ฑ์—์„œ๋Š” ์†์„ฑ ํŒŒ์ผ ๋˜๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ์ด ๊ฐ’์„ ๊ฐ€์ ธ์˜ด.

ProductService or Mock ProductService๊ฐ€ ๋ฐ˜ํ™˜๋˜๋”๋ผ๋„ ํ•จ์ˆ˜ ์‹œ๊ทธ๋‹ˆ์ฒ˜์—๋Š” IProductService๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค๊ณ  ์ž‘์„ฑ๋˜์žˆ๋‹ค. => ๋‚˜์ค‘์— Another ProductService ๋ผ๋Š” ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ์ˆ˜์ •ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ, ์ƒˆ ํด๋ž˜์Šค ์„ ์–ธ์— implements IProductService๋ฅผ ์ž…๋ ฅํ•จ์œผ๋กœ์จ ํŒฉํ† ๋ฆฌ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๊ฐ€ ์ถ”๊ฐ€ ๋ณ€๊ฒฝ ์—†์ด ์ปดํŒŒ์ผ๋จ.

(์•„์ง ์ž˜ ๋ชจ๋ฅด๊ฒ ์Œ.)

๐ŸŒ ์š”์•ฝ

  • ํด๋ž˜์Šค ์ƒ์†์ด๋ž€ ๊ธฐ์กด์— ์ •์˜๋˜์žˆ๋Š” ํด๋ž˜์Šค์˜ ๋ชจ๋“  ๋ฉค๋ฒ„๋ฅผ ๋ฌผ๋ ค๋ฐ›์•„ ์ƒˆ๋กœ์šด ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ.
  • ์„œ๋ธŒ ํด๋ž˜์Šค์—์„œ ์Šˆํผ ํด๋ž˜์Šค์˜ public ๋˜๋Š” protected ํ”„๋กœํผํ‹ฐ ์‚ฌ์šฉO
  • ํด๋ž˜์Šค ํ”„๋กœํผํ‹ฐ๊ฐ€ private๋กœ ์„ ์–ธ๋œ ๊ฒฝ์šฐ ํด๋ž˜์Šค ๋‚ด๋ถ€์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ
  • private ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•ด ํ•œ๋ฒˆ๋งŒ ์ธ์Šคํ„ด์Šคํ™”ํ•  ์ˆ˜ ์žˆ๋Š” ํด๋ž˜์Šค ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ.
  • ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ์€ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์„œ๋ธŒ ํด๋ž˜์Šค๊ฐ€ ์Šˆํผ ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ๋ฅผ ํŠน์ • ํ˜•ํƒœ๋กœ ๊ตฌํ˜„ํ•˜์—ฌ ์žฌ์ •์˜ ํ•˜๋Š” ๊ฒƒ.
  • ํด๋ž˜์Šค ์ƒ์„ฑ์ž๋„ ์žฌ์ •์˜ ๊ฐ€๋Šฅ
  • superํ‚ค์›Œ๋“œ์™€ super() ๋ฉ”์„œ๋“œ๋กœ ์„œ๋ธŒ ํด๋ž˜์Šค๊ฐ€ ์Šˆํผํด๋ž˜์Šค์˜ ํด๋ž˜์Šค ๋ฉค๋ฒ„๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Œ.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ