设计模式

facade模式

2017-11-16  本文已影响0人  老练子丶2017

将几个类方法封装一起,外部不可见

facade.h

#ifndef _FACADE_H

#define _FACADE_H

#include <iostream>

using namespace std;

class Sub1

{

public:

Sub1() {}

~Sub1() {}

void operation() {

cout << "sub1" << endl;

}

};

class Sub2

{

public:

Sub2() {}

~Sub2() {}

void operation() {

cout << "sub2" << endl;

}

};

class facade

{

public:

facade() {

_sub1 = new Sub1;

_sub2 = new Sub2;

}

~facade() {}

void all() {

_sub1->operation();

_sub2->operation();

}

private:

Sub1* _sub1;

Sub2* _sub2;

};

#endif // _FACADE_H

facade.cpp

#include "facade.h"

int main()

{

facade* fa = new facade;

fa->all();

return 0;

}

编译:make facade

上一篇 下一篇

猜你喜欢

热点阅读