#include<iostream>
using namespace std;
//------------抽象层----------
//抽象的CPU类
class CPU {
public:
virtual void caculate() = 0;
};
//抽象的显卡类
class Aard {
public:
virtual void display() = 0;
};
//抽象内存类
class Memory {
public:
virtual void storage() = 0;
};
//架构类面相抽象类
class Computer {
public:
Computer(CPU*cpu, Aard*aard, Memory*memory) {
this->cpu = cpu;
this->aard = aard;
this->memory = memory;
}
void work() {
this->cpu->caculate();
this->aard->display();
this->memory->storage();
}
private:
CPU*cpu;
Aard*aard;
Memory*memory;
};
//------------------------------------
//--------------实现层----------------
//英特尔公司的CPU
class IntelCPU :public CPU {
public:
virtual void caculate() {
cout << "英特尔公司的CPU开始计算了!" << endl;
}
};
//英特尔公司的Aard
class IntelAard :public Aard {
public:
virtual void display() {
cout << "英特尔公司的显卡开始显示了!" << endl;
}
};
//英特尔
C++ 面向抽象类编程-电脑组装案例
最新推荐文章于 2022-08-15 22:51:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)