设计模式第七堂课
来源:互联网 发布:黄狮精 知乎 编辑:程序博客网 时间:2024/06/04 18:48
1. OCP (Open Close Principle)
A. Software entities like classes, modules and functions should beopen for extensionbut closed for modifications
B. The design and writing of the code should be done in a way that new functionality should be added with minimum changes in the existing code
C. The design should be done in a way to allow the adding of new functionality as new classes, keeping as much as possible existing code unchanged
1) usage
Being applied in those area which are most likely to be changed
2) liabilities
Making a flexible design involves additional time and effort spent for it and itintroduce new level of abstraction increasing the complexity of the code
Figure 1 A Design of Violating OCP
Figure 2 A Design of Following OCP
2. DIP (Dependency Inversion Principle) / Hollywood Principle
A. High-level modules should not depend on low-level modules. Both should depend on abstractions
B. Abstractions should not depend on details. Details should depend on abstractions
1) liabilities
Using this principle implies an increased effort, will result in more classes andinterfaces to maintain
Figure 3 A Design of Violating DIP
Figure 4 A Design of Following DIP
3. ISP (Interface Segregation Principle)
A. Clients should not be forced to depend upon interfaces that they don't use
1) liabilities
Requiring additional time and effort spent to apply it during the design timeand increase the complexity of code
Figure 5 A Design of Violating ISP
Figure 6 A Design of Following ISP
4. SRP (Single Responsibility Principle)
A. A class should have only one reason to change
1) liabilities
Increasing the complexity of code
Figure 7 Sample SRP
5. LSP (Liskov’s Substitution Principle)
A. Derived types must be completely substitutable for their base types
B. This principle is just an extension of the Open Close Principle
C. Making sure that new derived classes are extending the base classes without changing their behavior
Figure 8 A Design of Violating LSP
- 设计模式第七堂课
- 设计模式第七种原则
- 大话设计模式-第七夜
- 设计模式第七站--享元模式
- 第七篇 设计模式--原型模式
- 第七课 策略模式
- 第七个设计模式:抽象工厂
- js 设计模式 第七章 factory
- IOS设计模式第七篇之观察者设计模式
- 我的第七课:【设计模式】====中介者模式
- Android Ap 开发 设计模式第七篇:生成器模式
- Android App 开发 设计模式第七篇:生成器模式
- 大话设计模式java版本 第七章 代理模式
- 设计模式C++版:第七式代理模式
- 设计模式学习---第七节:简单工厂模式
- <<C++ Qt设计模式>>读书笔记一:第七章 库与设计模式
- 适配器模式和外观模式-《Head First 设计模式》第七章
- 《Android之大话设计模式》--设计模式之结构型模式 第七章:装饰模式 见MM的家长
- QDesktopServices::openUrl来打开网页
- Java中的字符串
- JavaScript Window - 浏览器对象模型
- 关于ffmpeg的安装详细步骤和说明
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- 设计模式第七堂课
- 和solr的N天N夜(二)--加入中文分词器
- Linux crontab 定时
- 设置JDeveloper工作空间
- 淘宝课程学习如何安排太原网络营销师强烈推荐
- 怎么理解Condition
- 使用Xcode7的Instruments检测解决iOS内存泄露
- 心急的C小加
- ORA-00392 ORA-00312 日志正在清除故障