#include <iostream>
using namespace std;
//
class CDeque
{
public:
void push_front() { cout<<"CDeque push_front."<<endl; }
void push_back() { cout<<"CDeque push_back."<<endl; }
void pop_front() { cout<<"CDeque pop_front."<<endl; }
void pop_back() { cout<<"CDeque pop_back."<<endl; }
};
struct ISequence
{
public:
virtual void push() = 0;
virtual void pop() = 0;
};
class CStack : public ISequence,CDeque
{
public:
virtual void push() { push_back(); }
virtual void pop() { pop_back(); }
};
class CQueue : public ISequence,CDeque
{
public:
virtual void push() { push_back(); }
virtual void pop() { pop_front(); }
};
//
void main()
{
CStack stack;
stack.push();
stack.pop();
CQueue queue;
queue.push();
queue.pop();
}
设计模式12:类适配器【结构型】
最新推荐文章于 2024-05-27 00:15:00 发布