typescript: model
/** * TypeScript 实体类 Model * https://stackoverflow.com/questions/12827266/get-and-set-in-typescript * https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines */ class UserInfo { id!: number; userName!: string; email!: string; } /** * 车辆实体类 */ class Car { //export /** * 序号 */ id!: number; /** * 座位 */ seats!: number; /** * 发动机 */ engine!: string; /* constructor(id, seats,engine){ this.id = id; this.seats = seats; this.engine=engine; }*/ /** * 序号 * @returns 返回序号 */ public getId(): number { //get return this.id; } /** * 座位数 * @returns 返回座位数 */ public getSeats(): number { //get return this.seats; } /** * 发动机 * @returns 返回发动机型号名称 */ public getEngine(): string { //get return this.engine; } /** * 设置座位数 * @param seats 输入数字座位数 */ public setSeats(seats: number) //set { this.seats=seats; } /** * 设置发动机型号 * @param engine 输入型号名称 */ public setEngine(engine: string) //set { this.engine=engine; } } /** * 继承 */ class Motorcycle extends Car { /* id!: number; seats!: number; engine!: string; constructor(id, seats,engine){ this.id = id; this.seats = seats; this.engine=engine; } public getId(): number { //get return this.id; } public getSeats(): number { //get return this.seats; } public getEngine(): string { //get return this.engine; } public setSeats(seats: number) //set { this.seats=seats; } public setEngine(engine: string) //set { this.engine=engine; }*/ } /* interface DuBuilder<Car>() .id(1) .setSeats("") .setEngine("") .build(); */ /** * 接口 */ interface Builder { /** * * @param seats */ setSeats(seats: number): this; /** * * @param engine */ setEngine(engine: string): this; } /** * 继承 Builder */ export class CarBuilder implements Builder { /** * 车信息类 */ private car: Car; /** * 实例化 */ constructor() { this.car = new Car(); } /** * 设置座位数 * @param seats 座位号 * @returns 返回座位号 */ public setSeats(seats: number): this { //this.car.setSeats(seats); this.car.setSeats(seats); return this; } /** * 设置发动机型号 * @param engine 发动机型号名称 * @returns */ public setEngine(engine: string): this { this.car.setEngine(engine); return this; } /** * 得到实体 * @returns 返回车信息类 */ public getResult(): Car { return this.car; } } class DuDirector { public buildFerrari(): Car { return new CarBuilder().setSeats(2).setEngine("V-12").getResult(); } public buildToyota(): Car { return new CarBuilder().setSeats(7).setEngine("V-6").getResult(); } public buildHonda(): Motorcycle { return new MotorcycleBuilder().setSeats(2).setEngine("V-4").getResult(); } public buildYamaha(): Motorcycle { return new MotorcycleBuilder().setSeats(1).setEngine("V-2").getResult(); } } /* */ class MotorcycleBuilder implements Builder { private motorcycle: Motorcycle; constructor() { this.motorcycle = new Motorcycle(); } public setSeats(seats: number): this { this.motorcycle.setSeats(seats); return this; } public setEngine(engine: string): this { this.motorcycle.setEngine(engine); return this; } public getResult(): Motorcycle { return this.motorcycle; } } /**/ const directorBu = new DuDirector(); directorBu.buildFerrari(); directorBu.buildToyota(); directorBu.buildHonda(); directorBu.buildYamaha(); const car = new CarBuilder().setSeats(2).setEngine("V-12").getResult(); const motorcycle = new MotorcycleBuilder() .setSeats(2) .setEngine("V-4") .getResult();
tsconfig.json
{ "compilerOptions": { "target": "ES5", "module": "CommonJS", "outDir": "./dist", "rootDir": "./src", "resolveJsonModule": true, "composite": true, // required on the dependency project for references to work https://github.com/microsoft/TypeScript/issues/30693 "sourceMap": true, "strictPropertyInitialization": false /*"emitDecoratorMetadata": false, "experimentalDecorators": true, "removeComments": false, "strict": true, "strictNullChecks": true,*/ //"declaration": false /* "strict": true, "experimentalDecorators": true, "useDefineForClassFields": false, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "esModuleInterop": true, "moduleResolution": "node", // Tells TypeScript to read JS files, as normally they are ignored as source files "allowJs": true, // Generate d.ts files "declaration": true, // go to js file when using IDE functions like "Go to Definition" in VSCode "declarationMap": true, // This compiler run should only output d.ts files "emitDeclarationOnly": true "lib": [ "es2017", "es2018" ]*/ }, "includes": [ "src/**/*.ts", "other-src/**/*.ts" ], "exclude":[ "rollup.config.js", "test", "dist", "node_modules", ], }
https://github.com/FreekPaans/PPPPayrollCaseStudy
https://github.com/bysoul/Payroll
https://github.com/GeekChao/Agile-Software-Development
https://www.typescriptlang.org/docs/handbook/modules.html
https://www.typescriptlang.org/docs/handbook/classes.html
https://www.koderhq.com/tutorial/typescript/get-set/
https://dev.to/jmalvarez/builder-pattern-in-typescript-3on0
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)