Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>;
- using namespace std;
- class Win {
- public:
- virtual void draw() = 0;
- virtual ~Win() { cout<<"Win deleted!\n"; }
- };
- class TextWin: public Win {
- private:
- int width, height;
- public:
- TextWin( int width, int height):width(width), height(height) {}
- void draw() {
- cout <<"TextWin: "<< width <<", "<< height << endl;
- }
- };
- class Decorator: public Win {
- private:
- Win* window;
- public:
- Decorator( Win* window ):window(window) {}
- void draw() {
- window->draw();
- }
- ~Decorator() { delete window; cout<<"Decorator deleted! "; }
- };
- class BorderDecorator: public Decorator {
- public:
- BorderDecorator( Win* window ): Decorator( window ) {}
- void draw() {
- cout << "Bordered ";
- Decorator::draw();
- }
- ~BorderDecorator() { cout<<"BorderDecorator deleted! "; }
- };
- class ScrollDecorator: public Decorator {
- public:
- ScrollDecorator( Win* window ): Decorator( window ) {}
- void draw() {
- cout << "Scrolled ";
- Decorator::draw();
- }
- ~ScrollDecorator() { cout<<"ScrollDecorator deleted! "; }
- };
- int main() {
- Win * a = new TextWin( 80, 15 ),
- * b = new BorderDecorator( new TextWin(60,25)),
- * c = new ScrollDecorator( new TextWin(70,24)),
- * d = new BorderDecorator( new ScrollDecorator( new TextWin(80,243)));
- a->draw();
- b->draw();
- c->draw();
- d->draw();
- cout <<"deleting a:\n"; delete a;
- cout <<"deleting b:\n"; delete b;
- cout <<"deleting c:\n"; delete c;
- cout <<"deleting d:\n"; delete d;
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment