light.h

 #ifndef _LIGHT_H_
#define _LIGHT_H_ #include <iostream> class LIGHT {
public:
void dim(int level) { std::cout << "LIGHT dim to " << level << std::endl; }
}; #endif

popper.h

 #ifndef _POPPER_H_
#define _POPPER_H_ #include <iostream> class POPPER {
public:
void on() { std::cout << "POPPER on" << std::endl; }
void pop() { std::cout << "POPPER pop" << std::endl; }
};
#endif

facade.h

 #ifndef _FACADE_H_
#define _FACADE_H_ #include "light.h"
#include "popper.h" class FACADE {
private:
POPPER & popper;
LIGHT & light;
public:
FACADE(POPPER &_popper, LIGHT &_light) : popper(_popper), light(_light) {}
void watch_movie() {
popper.on();
popper.pop();
light.dim();
}
};
#endif

main.cpp

 #include "facade.h"

 int main()
{
LIGHT light;
POPPER popper;
FACADE facade(popper, light);
facade.watch_movie();
}
05-11 04:24