装饰模式

Decorator.hpp

#ifndef DECORATOR_HPP_
#define DECORATOR_HPP_
class Frame {
public:
    virtual void createtoobar()=0;
    virtual void createWin()=0;
};

class WindowFrame: public Frame {
public:
    void createWin();

    void createtoobar();

};

class WindowDecortorFrame: public Frame {
public:
    void createWin();

    void createtoobar();

    void createBootomtoobar();
};

class MaxWinFrame: public WindowDecortorFrame {
public:
    void createWin();

    void createtoobar();
    void createBootomtoobar();
};

class MinWinFrame: public WindowDecortorFrame {
public:
    void createWin();
    void createtoobar();

    void createBootomtoobar();
};
class PhoneWinFrame: public WindowDecortorFrame {
public:
    void createWin();
    void createtoobar();
    void createBootomtoobar();
};
#endif /* DECORATOR_HPP_ */

Decorator.cpp

#include <iostream>
#include  "Decorator.hpp"
using namespace std;

void WindowFrame::createWin() {
    cout << "winframe create win success" << endl;
}
void WindowFrame::createtoobar() {
    cout << "winframe  create tooba successr" << endl;
}
void WindowDecortorFrame::createWin() {
    cout << "添加背景为红   装饰类 WindowDecortorFrame create win  success" << endl;
}

void WindowDecortorFrame::createtoobar() {
    cout << "添加背景为红   装饰类 WindowDecortorFrame   create tooba successr" << endl;
}

void WindowDecortorFrame::createBootomtoobar() {
    cout << "添加背景为红   装饰类 WindowDecortorFrame   create tooba successr" << endl;
}

void MaxWinFrame::createWin() {
    cout << "背景为红  宽屏WindowDecortorFrame ..MaxWinFrame  ..  create win  success"
            << endl;
}

void MaxWinFrame::createtoobar() {
    cout << "背景为红 宽屏WindowDecortorFrame ..MaxWinFrame  ..   create tooba successr"
            << endl;
}
void MaxWinFrame::createBootomtoobar() {
    cout
            << "背景为红  宽屏WindowDecortorFrame ..MaxWinFrame  ..   createBootomtoobar successr"
            << endl;
}

void MinWinFrame::createWin() {
    cout << "背景为红  窄屏WindowDecortorFrame ..MinWinFrame  .. create win  success"
            << endl;
}

void MinWinFrame::createtoobar() {
    cout << "背景为红  窄屏WindowDecortorFrame ..MinWinFrame  ..   create tooba successr"
            << endl;
}

void MinWinFrame::createBootomtoobar() {
    cout
            << "背景为红  窄屏WindowDecortorFrame ..MaxWinFrame  ..   createBootomtoobar successr"
            << endl;
}

void PhoneWinFrame::createWin() {
    cout << "背景为红  手机WindowDecortorFrame ..PhoneWinFrame  .. create win  success"
            << endl;
}

void PhoneWinFrame::createtoobar() {
    cout << "背景为红  手机WindowDecortorFrame ..PhoneWinFrame  ..   create tooba successr"
            << endl;
}
void PhoneWinFrame::createBootomtoobar() {
    cout
            << "背景为红  手机WindowDecortorFrame ..MaxWinFrame  ..   createBootomtoobar successr"
            << endl;
}

test.cpp

#include <iostream>
#include  "Decorator.hpp"
using namespace std;

int main() {

    Frame* winframe1 = new WindowFrame();
    winframe1->createWin();
    winframe1->createtoobar();

    Frame* winframe = new MaxWinFrame();
    winframe->createWin();
    winframe->createtoobar();

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值