//main.cpp
#include <iostream>
#include "class.h"
using namespace std;
int main(int argc, char** argv) {
TextView textView;
VScroll vs_TextView(&textView);
HScroll hs_vs_TextView(&vs_TextView);
Border b_hs_vs_TextView(&hs_vs_TextView);
b_hs_vs_TextView.draw();
return 0;
}
//class.h
#ifndef class_h
#define class_h
#include <iostream>
using namespace std;
class Component{
public:
virtual ~Component(){}
virtual void draw() = 0;
};
class TextView:public Component{
public:
void draw(){
cout << "TextView. " << endl;
}
};
class Decorator:public Component{
Component* _component;
public:
Decorator(Component* component):_component(component){}
virtual void addon() = 0;
void draw(){
addon();
_component->draw();
}
};
class Border:public Decorator{
public:
Border(Component* component):Decorator(component){}
void addon(){cout << "Bordered ";}
};
class HScroll:public Decorator{
public:
HScroll(Component* component):Decorator(component){}
void addon(){cout << "HScrolled ";}
};
class VScroll:public Decorator{
public:
VScroll(Component* component):Decorator(component){}
void addon(){cout << "VScrolled ";}
};
#endif