devStandard/docs/learning/b-js设计模式/常见的设计模式.md
2025-03-29 14:35:49 +08:00

29 lines
785 B
Markdown
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 设计模式
> 设计模式主要目的是提升代码可扩展性以及可阅读性
参考:
* JavaScript设计模式与开发实践》
* https://segmentfault.com/a/1190000020179009
**单例模式**
**策略模式**
**模板方法模式**
**职责链模式**
**发布订阅模式(观察者模式)**
- 单一职责原则(`SRP`) 一个对象(只做一件事)。
- 代理模式,迭代器模式,单例模式,装饰者模式
- 最少知识原则(`LKP`) 一个软件实体应当尽可能少地与其他实体发生相互作用。
- 中介者模式
- 开放-封闭原则(`OCP`):软件实体(类,模块,函数)应该都是可以扩展,但是不可修改
- 发布-订阅模式,模板方法模式,策略模式,代理模式,职责链模式