/*

功能:定义一个操作数据库的库  支持 Mysql Mssql  MongoDb

要求1:Mysql MsSql  MongoDb功能一样  都有 add  update  delete  get方法    

注意:约束统一的规范、以及代码重用

解决方案:需要约束规范所以要定义接口 ,需要代码重用所以用到泛型

    1、接口:在面向对象的编程中,接口是一种规范的定义,它定义了行为和动作的规范
2、泛型 通俗理解:泛型就是解决 类 接口 方法的复用性、 */ //操作用户表 定义一个User类和数据表做映射 import {MsSqlDb} from './modules/db' class User{
username:string | undefined;
password:string | undefined;
} var u=new User();
u.username='张三2222';
u.password='123456'; var oMssql=new MsSqlDb<User>();
oMssql.add(u);
interface DBI<T>{
add(info:T):boolean;
update(info:T,id:number):boolean;
delete(id:number):boolean;
get(id:number):any[];
} //定义一个操作mysql数据库的类 注意:要实现泛型接口 这个类也应该是一个泛型类 export class MysqlDb<T> implements DBI<T>{ constructor(){ console.log('数据库建立连接');
}
add(info: T): boolean { console.log(info); return true; } update(info: T, id: number): boolean {
throw new Error("Method not implemented.");
}
delete(id: number): boolean {
throw new Error("Method not implemented.");
}
get(id: number): any[] {
var list=[ {
title:'xxxx',
desc:'xxxxxxxxxx'
},
{
title:'xxxx',
desc:'xxxxxxxxxx'
}
] return list;
} } //定义一个操作mssql数据库的类 export class MsSqlDb<T> implements DBI<T>{ constructor(){ console.log('数据库建立连接');
}
add(info: T): boolean {
console.log(info);
return true;
}
update(info: T, id: number): boolean {
throw new Error("Method not implemented.");
}
delete(id: number): boolean {
throw new Error("Method not implemented.");
}
get(id: number): any[] { var list=[ {
title:'xxxx',
desc:'xxxxxxxxxx'
},
{
title:'xxxx',
desc:'xxxxxxxxxx'
}
] return list;
} }

typeScript模块<四>的更多相关文章

  1. es6模块 nodejs模块和 typescript模块

    es6模块 import和export nodejs模块 require和module.exports typescript模块 module和export

  2. TypeScript模块系统、命名空间、声明合并

    命名空间 命名空间能有效避免全局污染.在ES6引入模块之后,命名空间就较少被提及了.如果使用了全局的类库,命名空间仍是一个好的解决方案. namespace Shape{ const pi = Mat ...

  3. typeScript模块<三>

    /*模块 1 模块的的概念 2 模块导出的几种方法 1.export 导出声明 2.export 导出语句 3.export default 4.import导入模块 3 模块化封装上一讲的DB库 * ...

  4. typeScript模块<二>

    /*模块 1 模块的的概念 2 模块导出的几种方法 1.export 导出声明 2.export 导出语句 3.export default 4.import导入模块 3 模块化封装上一讲的DB库 * ...

  5. typeScript模块<一>

    /*模块 模块的的概念 模块导出的几种方法 1.export 导出声明 2.export 导出语句 3.export default 4.import导入模块 模块化封装上一讲的DB库 */ /* 模 ...

  6. typescript 模块

    模块:模块可以帮助开发者将代码分割为重用的单元.开发者可以自己决定将模块中的哪些资源(类,方法,变量)暴露出去供外部使用,哪些资源只在模块内使用 在ts里面,一个文件就是一个模块,并没有什么特殊的标识 ...

  7. TypeScript 模块系统

    https://www.cnblogs.com/niklai/p/5808789.html

  8. 转载:《TypeScript 中文入门教程》 7、模块

    版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 关于术语的一点说明: 请务必注意一点,TypeScript 1.5里术语名已经发生了变 ...

  9. TypeScript Modules(模块)

    本文概述了TypeScript中如何使用模块以各种方式来组织代码.我们将涵括内部和外部的模块,并且讨论他们在适合在何时使用和怎么使用.我们也会学习一些如何使用外部模块的高级技巧,并且解决一些当我们使用 ...

随机推荐

  1. event.target事件

    event.target <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  2. linux远程工具

    实际工作中,linux系统都不会在我们自己的电脑上,linux系统安装在机房的服务器上,我们操作linux不可能跑到机房去,所以我们需要有一个工具,能在公司通过网络远程连接到机房的linux服务器上 ...

  3. Hibernate中的Session

    我们之前也经常使用Session,通过连接服务器将需要保存的值存到服务器的session中,这是之前关于session的简单应用.现在看到Hibernate框架中也有关于Session的定义,该定义是 ...

  4. Union-Find(并查集): Dynamic Connectivity 问题

    设计算法一般所使用的方法过程 什么是Dynamic connectivity 我们的problem就是支持这两种操作: Union与connected query Example 问题是两个objec ...

  5. machine learning (4)---feature scaling

    feature scaling:缩小或扩大feature的值,使所有的feature处于类似的范围,这样进行gradient descnet时更快趋向最小值.因为不同的feature的范围相差很大时, ...

  6. python 杂记20191102

    上下文管理器: def __exit__(self, exc_type, exc_val, exc_tb):若exc_tb不是空,则说明有异常返回值只能是true或false,若是false,则会把之 ...

  7. C++创建对象的3种方式(转载)

    #include <iostream> using namespace std; class A { private: int n; public: A(int m):n(m) { } ~ ...

  8. jquery定义链接跳转的高亮显示

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. Oracle substr() 字符截取函数

    1.substr函数格式   (俗称:字符截取函数) 格式1: substr(string string, int a, int b); 格式2:substr(string string, int a ...

  10. C语言利用fgetc复制拷贝文件内容

    #include <stdio.h> #include <stdlib.h> //文件的内容复制 int main(int a,char *argv[]){ if(a!=3){ ...