类和类之间有什么关系
Object Oriented Programming, Object Oriented Design / OOP,OOD

- Inheritance
- Composition
- Delegation
Composition(复合),表示 has-a

变化一下以便于理解

我里面有另一种这个东西
黑色菱形表示复合
这是一个特例
queue里面全部用的是 c 的功能。
deque 里面可能有100个功能,queue 只用了6了
Adapter 适配
已有的deque功能完全满足,只不过变了个名字
并不是所有的 Composition 都长这个样子
从内存的角度讲解 Composition

Composition关系下的构造和析构

构造时由内向外
析构时由外向内
Delegation(委托). Composition by reference.

指针指向另一个类
空心表示指针,引用只是一个指针,暂时还没有
pimpl
pointer to implementary 指针到实现
编译防火墙
Inheritance(继承),表示 is-a

三者都是面向对象的一部分
空心三角新表示继承
Inheritance(继承)关系下的构造和析构

Inheritance with virtual functions(虚函数)

成员函数分为三种
non-virtual 函数,虚函数:你不希望 derived class 重新定义(override,复写)
virtual 函数:你希望 derived class 重新定义(override,复写)
pure virtual 函数:你希望 derived class 一定要重新定义它,你对它没有默认定义。
Inheritance with virtual


23个重要模式之一
Template Method
MFC

Inheritance + Composition 关系下的构造与析构


Delegation + Inheritance





Prototype
下划线代表静态
-Private
# Protected
+Public


网友评论