Typescript中接口、类、泛型综合使用

//定义接口统一 各个数据库类中拥有的方法
interface DBI<T>{
    add(value:T):boolean;
    update(info:T,id:number):boolean;
    delete(id:number):boolean;
    get(id:number):any;
}
//定义一个操作MysqlDb的类
class MysqlDB<T> implements DBI<T>{
    constructor(){
        console.log("建立连接");
    }
    add(value: T): boolean {
        console.log(value);
       return true;
    }    
    update(info: T, id: number): boolean {
        console.log(info,id);
        return true;
    }
    delete(id: number): boolean {
        console.log(id);
        return true;
    }
    get(id: number) {
        console.log(id);
    }
}
// 定义一个操作OracleDB的类
class OracleDB<T> implements DBI<T>{
    constructor(){
        console.log("建立连接");
    }
    add(value: T): boolean {
        console.log(value);
       return true;
    }    
    update(info: T, id: number): boolean {
        console.log(info,id);
        return true;
    }
    delete(id: number): boolean {
        console.log(id);
        return true;
    }
    get(id: number) {
        console.log(id);
    }
}
//假如操作用户表 定义一个user类和数据表做映射
class User{
    username:string | undefined;
    password:string | undefined;
    constructor(parems:{
        username:string | undefined,
        password:string | undefined
    }){
        this.username = parems.username;
        this.password = parems.password;
    }
}
//实例化user类
var u = new User({
    username:"lisi",password:"123"
});
var mysqlDB = new MysqlDB<User>();
mysqlDB.add(u);
//实例化user类
var u = new User({
    username:"wangwu",password:"234343"
});
var oracleDB = new OracleDB<User>();
oracleDB.add(u);