外观模式(Facade Pattern),亦称"过程模式"。外观模式为一组具有类似功能的类群,比如类库,子系统等,提供一个一致的简单的界面。这个简单的界面被称之为facade。适用于:为子系统统一一套接口,使子系统更加容易使用。
Facade.h
#pragma once
#include<iostream>
#include<string>
// 子系统
class SubSystemA
{
public:
SubSystemA() {};
~SubSystemA() {};
void doThing(void) { std::cout << "SubSystemA()" << std::endl; }
private:
};
// 子系统
class SubSystemB
{
public:
SubSystemB() {};
~SubSystemB() {};
void doThing(void) { std::cout << "SubSystemB()" << std::endl; }
private:
};
// 子系统
class SubSystemC
{
public:
SubSystemC() {};
~SubSystemC() {};
void doThing(void) { std::cout << "SubSystemC()" << std::endl; }
private:
};
class Facade
{
public:
Facade()
{
m_sysA = new SubSystemA;
m_sysB = new SubSystemB;
m_sysC = new SubSystemC;
};
~Facade()
{
delete m_sysA;
delete m_sysB;
delete m_sysC;
};
void doThings()
{
m_sysA->doThing();
m_sysB->doThing();
m_sysC->doThing();
}
private:
SubSystemA * m_sysA;
SubSystemB * m_sysB;
SubSystemC * m_sysC;
};
Facade.cpp
#include "Facade.h"
mainTest.cpp
#include<iostream>
#include"Facade.h"
int main(void)
{
Facade* facade = new Facade;
facade->doThings();
delete facade;
system("pause");
return 0;
}