// Typescript
// 추상화
abstract class Product{
name: string;
price: number;
constructor(name: string, price: number){
this.name = name;
this.price = price;
}
}
// 상속
export class TV extends Product{
size: number;
constructor(name: string, price: number, size: number){
super(name, price)
this.size = size;
}
}
export class Laptop extends Product{
weight: number;
constructor(name: string, price: number, weight: number){
super(name, price); // 부모 클래스 호출
this.weight = weight;
}
// 캡슐화
getWeight(){
return `${this.weight}Kg`
}
setWeight(weight: number){
if(weight < 0){
throw Error
}
this.weight = weight
}
}
const samsungTv = new TV('SSTV', 300, 56);
console.log(samsungTv);
const samsungLaptop = new Laptop('SSNOTEBOOK', 100, 3);
console.log(samsungLaptop.name, samsungLaptop.getWeight());
// Javascript
class Person{
constructor(name, age){
this.name = name;
this.age = age;
}
}
const kim = new Person('jun', 33);
logger.info(kim);
'Study > 끄적끄적' 카테고리의 다른 글
Protobuf send 전 size 체크 (0) | 2024.09.05 |
---|---|
ORM 없이 DB 접속하기 (1) | 2024.09.02 |
Regex) password validation (0) | 2022.12.26 |
DB) database 셋팅을 맞추다 정리한 것들 (Code Convention) (0) | 2022.12.16 |
Javascript) Object Inheritance (0) | 2022.06.17 |