Skip to content

Instantly share code, notes, and snippets.

남현욱 hw0k

Block or report user

Report or block hw0k

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View index.ts
class File implements Input {
getString(): string {
return 'File Input';
}
}
class Monitor implements Output {
writeString(str: string): void {
console.log(`writed ${str} to monitor.`);
}
View index.ts
class Keyboard implements Input {
getString(): string {
return 'Keyboard Input';
}
}
class Console implements Output {
writeString(str: string): void {
console.log(`writed ${str} to console.`);
}
View index.ts
interface Input {
getString(): string;
}
interface Output {
writeString(str: string): void;
}
class Task {
static copy(input: Input, output: Output) {
View index.ts
class Keyboard {
getString(): string {
return '사랑해요 여러분';
}
}
class Console {
writeString(str: string): void {
console.log(`writed ${str} to console.`);
}
View index.ts
const rec: Shape = new Rectangle(3, 4);
console.log(rec.area); // 12
const sq: Shape = new Square(4);
console.log(sq.area); // 16
View index.ts
// Shape 인터페이스는 넓이를 구할 수 있는 것(기하학 관점의 면)이라고 가정한다.
interface Shape {
readonly area: number;
}
class Rectangle implements Shape {
constructor(public width: number, public height: number) {}
public get area() {
return this.width * this.height;
View index.ts
const rec: Rectangle = new Rectangle();
rec.width = 3;
rec.height = 4;
console.log(rec.area === 12); // true
const rec2: Rectangle = new Square();
rec2.width = 3;
rec2.height = 4;
View index.ts
class Rectangle {
protected _width: number = -1;
protected _height: number = -1;
public get width() {
return this._width;
}
public set width(w: number) {
this._width = w;
}
View index.ts
interface Animal {
eat(): void;
sleep(): void;
cry(): void;
}
interface Flyable {
fly(): void;
}
View index.ts
interface Animal {
eat(): void;
sleep(): void;
cry(): void;
}
interface FlyableAnimal extends Animal {
fly(): void;
}
You can’t perform that action at this time.