说人话:将同名接口 统一成一个接口
.h
class Mouse
{
public:
void get_information();
};
class Keyboard
{
public:
void get_information();
};
class Screen
{
public:
void get_information();
};
class integrate
{
public:
integrate(Mouse* M, Keyboard* K, Screen* S);
~integrate();
void get_information();
private:
Mouse* M;
Keyboard* K;
Screen* S;
};
.cpp
int main()
{
Mouse* M = new Mouse;
Keyboard* K = new Keyboard;
Screen* S = new Screen;
integrate* i = new integrate(M,K,S);
i->get_information(); //统一接口,不然就要调用三次接口
delete i;
i = nullptr;
return 0;
}
void Mouse::get_information()
{
cout << "我是鼠标!" << endl;
}
void Keyboard::get_information()
{
cout << "我是键盘!" << endl;
}
void Screen::get_information()
{
cout << "我是屏幕!" << endl;
}
integrate::integrate(Mouse* M, Keyboard* K, Screen* S)
{
this->M = M;
this->K = K;
this->S = S;
}
integrate::~integrate()
{
delete this->M;
delete this->K;
delete this->S;
}
void integrate::get_information()
{
this->M->get_information();
this->K->get_information();
this->S->get_information();
}