public 继承为接口继承, private 继承为实现继承
/*Adapter.h*/
#ifndef ADAPTER_H
#define ADAPTER_H
class Target
{
public:
Target();
virtual ~Target();
virtual void Request();
protected:
private:
};
class Adaptee
{
public:
Adaptee();
~Adaptee();
void SpecificReqeust();
protected:
private:
};
class Adapter:public Target,private Adaptee
{
public:
Adapter();
~Adapter();
void Request();
};
#endif
/*Adapter.cpp*/
#include "Adapter.h"
#include <iostream>
Target::Target()
{
}
Target::~Target()
{
}
void Target::Request()
{
std::cout<<"Request..."<<std::endl;
}
Adaptee::Adaptee()
{
}
Adaptee::~Adaptee()
{
}
void Adaptee::SpecificRequest()
{
std::cout<<"SpecifiRequest..."<<std::endl;
}
Adapter::Adapter()
{
}
Adapter::~Adapter()
{
}
void Adapter::Request()
{
this->SpecificRequest();
}
/*main.cpp*/
#include "Adapter.h"
int main()
{
Target *adt=new Adapter();
adt->Request();
return 0;
}