1. 六大设计原则
单一职责原则
1 | 一个类只负责一件事 |
开闭原则
1 | 对修改关闭, 对扩展开放 |
接口隔离原则
1 | // 如 Tableview的 delegate处理事件回调/ dataSource处理数据源 |
依赖倒置原则
1 | 抽象不应该依赖于具体实现, 具体实现可以依赖于抽象 |
里氏替换原则
1 | // 如KVO |
迪米特原则
1 | 一个对象应当对其他对象有尽可能少的了解 |
2. 责任链
1 | @class BusinessObject; |
3. 桥接
1 | // MARK: - 桥接 |
4. 适配器
1 | // 原有类 |
1 | // 适配类 |
5. 单例
1 | #import "Mooc.h" |
6. 命令
简述: 行为参数化
功能: 降低代码重合度
总结
手写单例实现
OC实现见上文
swift
版本:
1 | class Singleton { |
了解哪些设计原则, 谈谈理解
六大原则
简洁表述桥接模式的主体结构
依赖倒置原则
UI事件传递机制怎么实现的? 其中运用了哪些设计模式? 怎么理解
UI视图: 单一职责原则, 事件传递: 责任链设计模式
- 本文作者: 醉疏狂
- 本文链接: https://hubin97.github.io/2020/05/20/设计模式/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!