上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 58 下一页
摘要: 中介者模式 如图,左边的这种相互的沟通会非常出杂乱,复杂。严重不符合开放封闭原则,其中一个对象改了,就牵扯到很多的对象。右边的,如果一个对象改了,只要改中介者就行 举个例子:比如买房子,a,b分别是买房子和卖房子的两个人 // 中介者 class Mediator { constructor(a, 阅读全文
posted @ 2019-11-16 21:06 wzndkj 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 备忘录模式:随时记录一个对象的状态变化,随时可以恢复之前的某个状态(如撤销功能) // 状态备忘 class Memento { constructor(content) { this.content = content; } getContent() { return this.content; 阅读全文
posted @ 2019-11-16 20:50 wzndkj 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 命令模式:执行命令时,发布者和执行者分开(比如老板和服务员,老板说谁谁谁去干什么,然后服务员就去干了,这适合人比较少,一吆喝就都知道了。如果是上千人,这样就不合适了,这个时候需要发布者和执行者分开)。中间加入命令对象,作为中转站。 比如战争片中,将军传递命令 class Receiver { exe 阅读全文
posted @ 2019-11-16 08:17 wzndkj 阅读(237) 评论(0) 推荐(0) 编辑
摘要: class Action { handle() { handle1(); handle2(); handle3(); } handle1() { console.log('1'); } handle2() { console.log('2'); } handle3() { console.log(' 阅读全文
posted @ 2019-11-16 08:00 wzndkj 阅读(302) 评论(0) 推荐(0) 编辑
摘要: 策略模式:不同策略分开处理,避免出现大量 if...else 或者 switch...case class User { constructor(type) { this.type = type; } buy() { if (this.type 'ordinary') { console.log(' 阅读全文
posted @ 2019-11-15 07:04 wzndkj 阅读(216) 评论(0) 推荐(0) 编辑
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2019-11-15 06:51 wzndkj 阅读(3) 评论(0) 推荐(0) 编辑
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2019-11-15 06:41 wzndkj 阅读(3) 评论(0) 推荐(0) 编辑
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2019-11-14 07:00 wzndkj 阅读(2) 评论(0) 推荐(0) 编辑
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2019-11-14 06:45 wzndkj 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 状态模式:一个对象有状态变化,每次状态变化都会触发一个逻辑,不能总是用if...else来控制 比如红绿灯 uml类图 代码 // 状态(红灯,绿灯 黄灯) class State { constructor(color) { this.color = color; } // 设置状态 handle 阅读全文
posted @ 2019-11-13 07:20 wzndkj 阅读(636) 评论(0) 推荐(0) 编辑
上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 58 下一页