2.0.1 • Published 1 year ago

ts-design-mode v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

简述 Description

  • 使用ts做设计模式的话,就会更加严格,成为强语言,更接近于java了,开发起来更加繁琐,但同时也更加规范,平时写些简单的前端没有必要特别规范,或者使用ts写复杂设计模式,不利于项目交接和后续开发人员的理解和维护,但熟悉也是有必要的. 编辑器提示也挺方便
  • When coding design pattern in typescript,it should be strict and almost near JAVA,which should be cumbersome for coding. At the same time, more standard and using editors like vscode is easy. However,this is hard for someone who just simple coding and focused on business in work.It not suggested due to it's difficult for others who will take over the project.

备注 Remark

  • 所有的 .js 文件都可以删掉重新生成
  • All of the *.js files can be deleted and rebuild use the next command.
tsc index

参考地址 Reference address

https://www.runoob.com/design-pattern/design-pattern-tutorial.html

全局安装typescript 、 ts-node 和 运行库. Execute the next lines,lodash

npm install -g typescript
npm install -g ts-node
npm install -D tslib @types/node (// ts 运行时库,包含所有ts辅助函数)
npm i --save-dev @types/lodash

目录结构 Directory structure

  • modes 为所有的设计模式代码 all of the design patterns code
  • test 为参考测试代码 testing demo

使用 Using

  • 直接使用 using directly,ignore chinese and run
    • 运行 ts-node test/factory
    • 或者 or
    • 编译 tsc test/factory 运行 node test/factory
  • npm调用 using npm
    • npm run factory
  • 外部调用 using outside
    • 参考test代码 reference the code in test directly

介绍 Introduce

创建型模式 Creation Patterns

  • factory 工厂模式:将创建对象的过程抽象成工厂的方法
  • abstract-factory 抽象工厂模式:属于工厂的工厂,用于系类产品有多于一个产品族,一个产品族中多个对象一起工作
  • singleton 单例模式:分为两种加载 懒汉式/饿汉式,提供全局访问唯一对象的方式
  • builder 建造者模式:使用多个简单的对象一步一步构建成一个复杂对象,多个子对象可能会发生改变,但把它们组合在一起的算法相对稳定
  • prototype 原型模式:直接创建对象代价比较大时,用于创建当前对象的克隆,通常与工厂模式一起出现

结构型模式 Structural Patterns

  • adapter 适配器模式:是作为两个不兼容接口之间的桥梁。就是让mp3播放器播放mp4
  • bridge 桥接模式:用于把抽象化和实现化解耦,使得二者可以独立变化。一个作为桥接的接口
  • filter 过滤器模式/标准模式:使用不同标准过滤一组对象。
  • composite 组合模式/整体模式:把一组相似的对象当成一个单一的对象,用来表示部分整体层次,创建了对象组的树形结构
  • decorator 装饰器模式:允许向一个现有的对象添加新的功能,同时不改变其结构,作为现有类的一个包装
  • facade 外观模式:为客户端提供一个可访问的接口,隐藏系统的复杂性
  • flyweight 享元模式:减少创建对象的数量,重用现有同类对象
  • proxy 代理模式:一个类代表另一个类的功能,创建具有现有对象的对象

行为型模式

  • chain 责任链模式:(chain of responsibility)为请求创建一个接收者对象的链。对请求发送者和接收者进行解耦。链条根据不同层级一层一层向下传递,就像 switch
  • command 命令模式:数据驱动的设计模式,用不同的请求对客户进行参数化,降低耦合
  • interpreter 解释器模式:实现了一个表达式接口,解释一个特定的上下文
  • iterator 迭代器模式:提供一种方法顺序访问一个聚合对象中各个元素,而又无需暴露该对象的内部标识
  • mediator 中介者模式:用来降低多个对象和类之间的通信复杂性。提供一个中介类,处理不同类之间的通信,支持松耦合,使代码易于维护(网状结构分离为星型结构)
  • memento 备忘录模式:保存一个对象的某个状态,以便在适当的时候恢复对象
  • observer 观察者模式:一对多关系时,使用观察者模式,改变通知所有依赖的对象
  • state 状态模式:类的行为是基于它的状态而改变的
  • null-object 空对象模式:一个空对象取代 NULL 对象实例的检查。Null对象不是检查空值,而是反应一个不做任何动作的关系。Null对象也在数据不可用时提供默认行为
  • strategy 策略模式:一个类的行为或其算法可以在运行时更改。(各种策略对象和行为随着策略对象改变而改变的context对象)
  • template 模板模式:抽象类定义了方法/模板,子类重写方法,但是调用以抽象类中定义的方法(通用方法)进行
  • visitor 访问者模式:使用一个访问者类,改变了元素类的执行算法。元素对象的执行算法随着访问者改变而改变

J2EE模式(关注表示层)

  • mvc MVC模式:模型-视图-控制器模式。用于应用程序的分层开发
  • delegate 业务代表模式,用于表示层与业务层解耦。客户端/业务代表/查询服务/业务服务
  • composite-entity 组合实体模式,用在EJB持久化机制中。一个组合实体就是一个EJB实体bean,代表了对象的图解。组合实体/粗粒度对象/依赖对象/策略
  • dao (Data Access Object Pattern)数据访问对象模式:把低级的数据访问API或操作从高级的业务服务中分离出来。数据访问对象接口层/数据访问对象实体类/模型对象/数值对象
  • front-controller 前端控制器模式:用来提供一个集中的请求处理机制,所有的请求都将由一个单一的处理程序处理。前端控制器/调度器/视图
  • intercepting 拦截过滤器模式:用于应用程序的请求或相应做一些预处理/后处理。认证、授权、记录日志。实体有 过滤器/过滤器链/Target/过滤管理器/客户端
  • locator 服务定位器模式:缓存要查询的服务。服务/Context/服务定位器/缓存/客户端
  • transfer 传输对象模式:从客户端向服务器一次性传递带有多个属性的数据,传输对象只读。业务对象/传输对象/客户端

其他 Others

  • 有些抱歉的是这个设计模式应该叫做 design patterns
1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

2.0.1

1 year ago

2.0.0

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.9

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.11

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago