#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
{
public:
virtual void push() { m_deque.push_back(); }
virtual void pop() { m_deque.pop_back(); }
private:
CDeque m_deque;
};
class CQueue : public ISequence
{
public:
virtual void push() { m_deque.push_back(); }
virtual void pop() { m_deque.pop_front(); }
private:
CDeque m_deque;
};
//
void main()
{
CStack stack;
stack.push();
stack.pop();
CQueue queue;
queue.push();
queue.pop();
}
设计模式11:对象适配器【结构型】
最新推荐文章于 2021-08-29 18:18:15 发布