Bridge(桥接模式)

#ifndef ABSTRACTION_H
#define ABSTRACTION_H
#include "Implementor.h"

class Abstraction
{
    public:
        /** Default constructor */
        Abstraction();
        /** Default destructor */
        virtual ~Abstraction();
        virtual void Operation();
        Implementor* m_pImp;
    protected:
    private:

};

#endif // ABSTRACTION_H

#include "Abstraction.h"
#include <windows.h>
Abstraction::Abstraction()
{
    m_pImp=NULL;
}

Abstraction::~Abstraction()
{
    if (NULL!=m_pImp)
    {
        delete m_pImp;
        m_pImp=NULL;
    }
}

void Abstraction::Operation()
{
   m_pImp->OperationImp();
}

#ifndef ATM_SX_H
#define ATM_SX_H

#include "Abstraction.h"


class ATM_SX : public Abstraction
{
    public:
        /** Default constructor */
        ATM_SX();
        /** Default destructor */
        virtual ~ATM_SX();
    protected:
    private:
};

#endif // ATM_SX_H

#include "ATM_SX.h"

ATM_SX::ATM_SX()
{
    //ctor
}

ATM_SX::~ATM_SX()
{
    //dtor
}

#ifndef IMPLEMENTOR_H
#define IMPLEMENTOR_H


class Implementor
{
    public:
        /** Default constructor */
        Implementor();
        /** Default destructor */
        virtual ~Implementor();
        virtual void OperationImp()=0;
    protected:
    private:
};

#endif // IMPLEMENTOR_H

#include "Implementor.h"

Implementor::Implementor()
{
    //ctor
}

Implementor::~Implementor()
{
    //dtor
}

#ifndef IMPLEMENTORA_H
#define IMPLEMENTORA_H

#include "Implementor.h"


class ImplementorA : public Implementor
{
    public:
        /** Default constructor */
        ImplementorA();
        /** Default destructor */
        virtual ~ImplementorA();
        void OperationImp();
    protected:
    private:
};

#endif // IMPLEMENTORA_H

#include "ImplementorA.h"
#include <iostream>
using namespace std;

ImplementorA::ImplementorA()
{
    cout<<"客户A来了"<<endl;
}

ImplementorA::~ImplementorA()
{
    cout<<"客户A走了"<<endl;
}

void ImplementorA::OperationImp()
{
    cout<<"客户A取钱"<<endl;
}

#ifndef IMPLEMENTORB_H
#define IMPLEMENTORB_H

#include "Implementor.h"


class ImplementorB : public Implementor
{
    public:
        /** Default constructor */
        ImplementorB();
        /** Default destructor */
        virtual ~ImplementorB();
         void OperationImp();
    protected:
    private:
};

#endif // IMPLEMENTORB_H

#include "ImplementorB.h"
#include <iostream>
using namespace std;

ImplementorB::ImplementorB()
{
    cout<<"客户B来了"<<endl;
}

ImplementorB::~ImplementorB()
{
    cout<<"客户B走了"<<endl;
}

void ImplementorB::OperationImp()
{
    cout<<"客户B取钱"<<endl;
}

#include <iostream>

using namespace std;
#include "ATM_SX.h"
#include "Abstraction.h"
#include "ImplementorA.h"
#include "ImplementorB.h"
int main()
{
    Abstraction* m_pATM=new ATM_SX();
    m_pATM->m_pImp=new ImplementorA();
    m_pATM->Operation();
    delete m_pATM;

    m_pATM->m_pImp=new ImplementorB();
    m_pATM->Operation();
    delete m_pATM;

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值