作者:youstar | 来源:互联网 | 2024-11-01 17:41
本书《C++设计模式精华:高效学习与速记指南》旨在帮助读者快速掌握C++设计模式的核心概念和应用技巧。书中详细介绍了继承这一重要机制,解释了派生类如何继承基类的属性和方法,并探讨了派生类对象如何存储和使用基类的数据成员。通过实例和代码示例,读者可以更好地理解继承在实际开发中的应用,从而提升编程效率和代码质量。
(读书笔记,结合书本看,如有冒犯请联系删除)
先掌握入门知识:
继承定义:派生类拥有基类的特征和方法叫做继承。
派生类的特性:
- 派生类对象存储了基类的数据成员。(派生类继承了基类的实现)
- 派生类可以使用基类的方法。(派生类继承了基类的接口)
- 派生类需要自己的构造函数。
- 派生类可以根据需要添加额外的数据成员和成员函数。
将源代码中的函数调用解释为执行特定的函数代码块被称为函数名联编(binding)。在编译过程中进行联编,称为静态联编(static binding)。编译器必须生成能够在程序运行时选择正确的虚方法的代码,被称为动态联编(dynamic binding)。
静态:所有静态持续变量在整个程序的执行期间都存在。
抽象基类(abstract base class,ABC):从两个需要继承的类中抽象出他们的共性,将这些特性放到一个ABC中,然后从该ABC分别派生出这两个类。这样,便可以使用基类指针数组同时管理这两个对象。C++通过纯虚函数(pure virtual function)提供未实现的函数。
内聚标志一个模块内各个元素彼此结合的紧密程度,它是信息隐蔽和局部化概念的自然扩展。 内聚是从功能角度来度量模块内的联系,一个好的内聚模块应当恰好做一件事。它描述的是模块内的功能联系。耦合是软件结构中各模块之间相互连接的一种度量,耦合强弱取决于模块间接口的复杂程度、进入或访问一个模块的点以及通过接口的数据。 程序讲究的是低耦合,高内聚。就是同一个模块内的各个元素之间要高度紧密,但是各个模块之间的相互依存度却要不那么紧密。
1.简单工厂模式(计算器)

2.策略模式

策略与工厂结合

3.装饰莫斯

4.代理模式

5.工厂方法模式

6.原型模式

7.模板方法模式

8.外观模式

9.建造者模式

10.观察这模式

11.抽象工厂模式

12.状态模式

13.适配器模式

14.备忘录模式

15.组合模式


17.单例模式

18.桥接模式

19.命令模式

20.责任链模式

21.中介者模式

22.享元模式

23.解释器模式

24.访问者模式
