今日完成了适配器模式的学习
#include <iostream>
using namespace std;
class Transportation
{
public:
virtual void drive(){}
};
class Car:public Transportation
{
public:
void drive()
{
cout<<"小轿车";
}
};
class Bus:public Transportation
{
public:
void drive()
{
cout<<"大巴";
}
};
class Road
{
public:
Transportation* transportation;
Road(Transportation* transportation)
{
this->transportation=transportation;
}
virtual void driveOnRoad(){}
};
class CementRoad:public Road
{
public:
CementRoad(Transportation* transportation):Road(transportation)
{
}
void driveOnRoad()
{
transportation->drive();
cout<<"行驶在水泥路"<<endl;
}
};
class BituminousRoad:public Road
{
public:
BituminousRoad(Transportation* transportation):Road(transportation)
{
}
void driveOnRoad()
{
transportation->drive();
cout<<"行驶在柏油路"<<endl;
}
};
int main()
{
Transportation* transportation;
Car car=Car();
transportation=&car;
CementRoad(transportation).driveOnRoad();
}