Index: typescript/src/index.ts =================================================================== diff -u -r6f0400ff0fa7b3a7fa58ab2fd42674d0bf0ebb82 -re981fb5b18ea68705478a7b16d62c5eb64614e7a --- typescript/src/index.ts (.../index.ts) (revision 6f0400ff0fa7b3a7fa58ab2fd42674d0bf0ebb82) +++ typescript/src/index.ts (.../index.ts) (revision e981fb5b18ea68705478a7b16d62c5eb64614e7a) @@ -3,11 +3,98 @@ import Person, { makePerson } from "./person/Person"; import * as R from 'ramda'; +import CarImpl from "./standard/CarImpl"; +import CarExtImpl from "./standard/CarExtImpl"; +import ObjExtCarImpl from "./standard/ObjExtCarImpl"; +//인터페이스로 객체 Person 을 만들어서 loop 돌리는 예제 let persons: IPerson[] = R.range(0, 5) .map((n: number) => new Person("이동민", 99)); - console.log(persons); -testMakePerson(); \ No newline at end of file +testMakePerson(); + + + +//object 타입으로 정확하게는 리터럴 객체 선언 +/** + * interface 인터페이스 이름 { + * key: type; + * key: type; + * } + */ + +interface UserInfo { + name:string, + age: number +} + +//기본적으로 Object 선언하는 방식으로 선언 +const user:UserInfo = { + name: "ryan", + age: 20, +} +console.log(user.name) // ryan + + + + +//리터럴 객체인데, 인터페이스의 타입을 다양하게 사용한 예제 +enum Gender { + Man, + Woman +} + +interface UserVariousInfo { + name: string; + age: number; + gender?: Gender; // 있어도 되고 없어도 되는 옵셔널 설멎(물음표) + readonly birth: number; //읽기 전용 + [key:number]: string; // 여러 속성 정보를 받을 때 사용 (key:number, value:string) +} + +//gender 포함 +const user1:UserVariousInfo = { + name: "ryan1", + age: 20, + gender: Gender.Man, + birth:19901210, +} + +//gedner 제외 +const user2:UserVariousInfo = { + name: "ryan2", + age: 22, + birth:19891225 +} + +//index 사용 +const user3:UserVariousInfo = { + name: "ryan2", + age: 22, + birth:19891225, + 1: "1반", + 2: "2번" +} +console.log("인터페이스 객체 -> " + user1.gender); +console.log("물음표 -> " + user2.gender); +console.log("키벨류 사용 -> " + user3["1"]); + + +// 진짜 인터페이스 사용은 이런것이다. +const carImpl = new CarImpl(); +console.log("<- CarImpl 사용 -> "); +carImpl.start(); +carImpl.stop(); + +// 인터페이스 확장 인스턴스 샘플 +const carExtImpl = new CarExtImpl(); +console.log("<- carExtImpl 사용 -> "); +carExtImpl.start(); +carExtImpl.sound(); +carExtImpl.stop(); + +const objExtCarImpl = new ObjExtCarImpl(); +console.log("<- 확장된 객체를 다시 확장한 인스턴스 사용 -> "); +objExtCarImpl.start(); \ No newline at end of file FishEye: Tag d2133460ec003f42375d401a6329c35714b65209 refers to a dead (removed) revision in file `typescript/src/standard/Car.ts'. FishEye: No comparison available. Pass `N' to diff? FishEye: Tag d2133460ec003f42375d401a6329c35714b65209 refers to a dead (removed) revision in file `typescript/src/standard/CarExt.ts'. FishEye: No comparison available. Pass `N' to diff? FishEye: Tag d2133460ec003f42375d401a6329c35714b65209 refers to a dead (removed) revision in file `typescript/src/standard/CarExtImpl.ts'. FishEye: No comparison available. Pass `N' to diff? FishEye: Tag d2133460ec003f42375d401a6329c35714b65209 refers to a dead (removed) revision in file `typescript/src/standard/CarImpl.ts'. FishEye: No comparison available. Pass `N' to diff? FishEye: Tag d2133460ec003f42375d401a6329c35714b65209 refers to a dead (removed) revision in file `typescript/src/standard/ObjExtCarImpl.ts'. FishEye: No comparison available. Pass `N' to diff?