- 分割したサブシステムへの入り口を1ヶ所にまとめる
- クライアントは必ずFacadeを経由してサブシステムを利用するので、サブシステム内の細かい単位を直接利用できなくなる
#include <iostream>
using namespace std;
// The 'Subsystem ClassA' class
class SubSystemOne {
public:
void MethodOne() {
cout << " SubSystemOne Method" << endl;
}
};
// The 'Sybsystem ClassB' class
class SubSystemTwo {
public:
void MethodTwo() {
cout << " SubSystemTwo Method" << endl;
}
};
// The 'Sybsystem ClassC' class
class SubSystemThree {
public:
void MethodThree() {
cout << " SubSystemThree Method" << endl;
}
};
// The 'Sybsystem ClassD' class
class SubSystemFour {
public:
void MethodFour() {
cout << " SubSystemFour Method" << endl;
}
};
// The 'Facade' class
class Facade {
public:
Facade() {
_one = new SubSystemOne();
_two = new SubSystemTwo();
_three = new SubSystemThree();
_four = new SubSystemFour();
}
virtual ~Facade() {
delete _one;
delete _two;
delete _three;
delete _four;
}
void MethodA() {
cout << endl << "MethodA() ---- " << endl;
_one->MethodOne();
_two->MethodTwo();
_four->MethodFour();
}
void MethodB() {
cout << endl << "MethodB() ---- " << endl;
_two->MethodTwo();
_three->MethodThree();
}
private:
SubSystemOne *_one;
SubSystemTwo *_two;
SubSystemThree *_three;
SubSystemFour *_four;
};
// client
int main() {
Facade *facade = new Facade();
facade->MethodA();
facade->MethodB();
delete facade;
return 0;
}
出力
MethodA() ----
SubSystemOne Method
SubSystemTwo Method
SubSystemFour Method
MethodB() ----
SubSystemTwo Method
SubSystemThree Method
参考サイト
最終更新:2012年03月16日 01:03