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;
}