1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| abstract class Database { constructor(public username: string = 'admin', public password: string = '123456') { this.username = username; this.password = password; } public abstract getDetails(): void public setDetails(username: string, password: string) { console.log(username, password); } }
class Sql extends Database { constructor(username: string, password: string) { super(username, password) } public getDetails() { const sqlUserName = this.username + 'Sql' const sqlPassWord = this.password + 'Sql' this.setDetails(sqlUserName, sqlPassWord) } }
class Mysql extends Database { constructor(username: string, password: string) { super(username, password) } public getDetails() { const mysqlUserName = this.username + 'Mysql' const mysqlPassWord = this.password + 'Mysql' this.setDetails(mysqlUserName, mysqlPassWord) } }
const ConnectSql = new Sql('aaa', 'bbb') ConnectSql.getDetails()
const ConnectMysql = new Mysql('cccc', 'ddd') ConnectMysql.getDetails()
|