cpp: Facade Pattern
/*****************************************************************//**
* \file GoldGraphic.h
* \brief Facade Pattern 外观模式
* 涂聚文 Geovin Du Visual Studio 2022 edit.
* \author geovindu
* \date May 2023
*********************************************************************/
#pragma once
#ifndef GOLDGRAPHIC_H
#define GOLDGRAPHIC_H
#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
using namespace std;
namespace DuFacadePattern
{
/// <summary>
/// 图形相关类
/// </summary>
class GoldGraphic
{
//--------------单件类实现相关begin----------------
private:
GoldGraphic() {};
GoldGraphic(const GoldGraphic& tmpobj);
GoldGraphic& operator = (const GoldGraphic& tmpobj);
~GoldGraphic() {};
public:
/// <summary>
///
/// </summary>
/// <returns></returns>
static GoldGraphic& getInstance()
{
static GoldGraphic instance;
return instance;
}
//--------------单件类实现相关end----------------
public:
/// <summary>
/// 是否全屏显示(true:是)
/// </summary>
/// <param name="enable"></param>
void display(bool enable)
{
cout << "图形->是否全屏显示->" << enable << endl;
//其他代码略......
}
/// <summary>
/// 是否开启特效(true:是)
/// </summary>
/// <param name="enable"></param>
void effect(bool enable)
{
cout << "图形->是否开启特效->" << enable << endl;
}
/// <summary>
/// 设置窗口分辨率
/// </summary>
/// <param name="index"></param>
void resolution(int index)
{
cout << "图形->分辨率设置选项->" << index << endl;
}
/// <summary>
/// 是否开启抗锯齿(true:是)
/// </summary>
/// <param name="enable"></param>
void antialiasing(bool enable)
{
cout << "图形->是否开启抗锯齿->" << enable << endl;
}
//其他接口略......
};
}
#endif
/*****************************************************************//**
* \file GoldSound.h
* \brief Facade Pattern 外观模式
* 涂聚文 Geovin Du Visual Studio 2022 edit.
* \author geovindu
* \date 20 May 2023
*********************************************************************/
#pragma once
#ifndef GOLDSOUND_H
#define GOLDSOUND_H
#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
using namespace std;
namespace DuFacadePattern
{
/// <summary>
/// 声音相关类
/// </summary>
class GoldSound
{
//--------------单件类实现相关begin----------------
private:
GoldSound() {};
GoldSound(const GoldSound& tmpobj);
GoldSound& operator = (const GoldSound& tmpobj);
~GoldSound() {};
public:
/// <summary>
///
/// </summary>
/// <returns></returns>
static GoldSound& getInstance()
{
static GoldSound instance;
return instance;
}
//--------------单件类实现相关end----------------
public:
/// <summary>
/// 是否开启背景声音(true:是)
/// </summary>
/// <param name="enable"></param>
void bgsound(bool enable)
{
cout << "声音->是否开启背景声音->" << enable << endl;
}
/// <summary>
/// 是否开启环境音效(true:是)
/// </summary>
/// <param name="enable"></param>
void envirsound(bool enable)
{
cout << "声音->是否开启环境音效->" << enable << endl;
}
/// <summary>
/// 是否开启表情声音(true:是)
/// </summary>
/// <param name="enable"></param>
void expsound(bool enable)
{
cout << "声音->是否开启表情声音->" << enable << endl;
}
/// <summary>
/// 音量大小设置(0-100)
/// </summary>
/// <param name="level"></param>
void setvolume(int level)
{
cout << "声音->音量大小为->" << level << endl;
}
//其他接口略......
};
}
#endif
/*****************************************************************//**
* \file GoldChatVoice.h
* \brief Facade Pattern 外观模式
* 涂聚文 Geovin Du Visual Studio 2022 edit.
*
* \author geovindu
* \date 20 May 2023
*********************************************************************/
#pragma once
#ifndef GOLDCHATVOLCE_H
#define GOLDCHATVOLCE_H
#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
using namespace std;
namespace DuFacadePattern
{
/// <summary>
///
/// </summary>
class GoldChatVoice
{
//--------------单件类实现相关begin----------------
private:
GoldChatVoice() {};
GoldChatVoice(const GoldChatVoice& tmpobj);
GoldChatVoice& operator = (const GoldChatVoice& tmpobj);
~GoldChatVoice() {};
public:
/// <summary>
///
/// </summary>
/// <returns></returns>
static GoldChatVoice& getInstance()
{
static GoldChatVoice instance;
return instance;
}
//--------------单件类实现相关end----------------
public:
/// <summary>
/// 麦克风音量大小设置(0-100)
/// </summary>
/// <param name="level"></param>
void micvolume(int level)
{
cout << "语音聊天->麦克风音量大小为->" << level << endl;
}
/// <summary>
/// 麦克灵敏度设置(0-100)
/// </summary>
/// <param name="level"></param>
void micsens(int level)
{
cout << "语音聊天->麦克风灵敏度为->" << level << endl;
}
/// <summary>
/// 聊天音量设置(0-100)
/// </summary>
/// <param name="level"></param>
void chatvolume(int level)
{
cout << "语音聊天->聊天音量为->" << level << endl;
}
//其他接口略......
};
}
#endif
/*****************************************************************//**
* \file GoldConffacade.h
* \brief Facade Pattern 外观模式
* 涂聚文 Geovin Du Visual Studio 2022 edit.
* \author geovindu
* \date May 2023
*********************************************************************/
#pragma once
#ifndef GOLDCONFFACADE_H
#define GOLDCONFFACADE_H
#include<cstring>
#include<stdbool.h>
#include<stdlib.h>
#include<iostream>
#include<malloc.h>
#include<cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <list>
#include <string>
#include <string.h>
#include "GoldChatVoice.h"
#include "GoldGraphic.h"
#include "GoldSound.h"
using namespace std;
namespace DuFacadePattern
{
/// <summary>
/// 扮演外观模式角色的类
/// </summary>
class GoldConffacade
{
//--------------单件类实现相关begin----------------
private:
GoldConffacade() {};
GoldConffacade(const GoldConffacade& tmpobj);
GoldConffacade& operator = (const GoldConffacade& tmpobj);
~GoldConffacade() {};
public:
/// <summary>
///
/// </summary>
/// <returns></returns>
static GoldConffacade& getInstance()
{
static GoldConffacade instance;
return instance;
}
//--------------单件类实现相关end----------------
public:
/// <summary>
/// 对于低配置电脑,只开启一些低配置选项
/// </summary>
void LowConfComputer()
{
GoldGraphic& g_gp = GoldGraphic::getInstance();
g_gp.display(true); //全屏耗费资源更低
g_gp.effect(false);
g_gp.resolution(2);
g_gp.antialiasing(false);
GoldSound& g_snd = GoldSound::getInstance();
g_snd.bgsound(false);
g_snd.envirsound(false);
g_snd.expsound(false);
g_snd.setvolume(15);
GoldChatVoice& g_cv = GoldChatVoice::getInstance();
g_cv.micvolume(20);
g_cv.micsens(50);
g_cv.chatvolume(60);
}
/// <summary>
/// 对于高配置电脑,能达到最好效果的项全部开启
/// </summary>
void HighConfComputer()
{
GoldGraphic& g_gp = GoldGraphic::getInstance();
g_gp.display(false);
g_gp.effect(true);
g_gp.resolution(0);
g_gp.antialiasing(true);
GoldSound& g_snd = GoldSound::getInstance();
g_snd.bgsound(true);
g_snd.envirsound(true);
g_snd.expsound(true);
g_snd.setvolume(50);
GoldChatVoice& g_cv = GoldChatVoice::getInstance();
g_cv.micvolume(100);
g_cv.micsens(100);
g_cv.chatvolume(100);
}
};
}
#endif
/*****************************************************************//**
* \file GeovinDu.cpp
* \brief Facade Pattern 外观模式
* 涂聚文 Geovin Du Visual Studio 2022 edit.
* \author geovindu
* \date 20 May 2023
*********************************************************************/
#include "GeovinDu.h"
#include "GoldChatVoice.h"
#include "GoldGraphic.h"
#include "GoldSound.h"
#include "GoldConffacade.h"
using namespace std;
namespace DuFacadePattern
{
/// <summary>
///
/// </summary>
void GeovinDu::displayFacade()
{
DuFacadePattern::GoldGraphic& g_gp = DuFacadePattern::GoldGraphic::getInstance();
g_gp.display(false);
g_gp.effect(true);
g_gp.resolution(2);
g_gp.antialiasing(false);
cout << "---------------" << endl;
DuFacadePattern::GoldSound& g_snd = DuFacadePattern::GoldSound::getInstance();
g_snd.setvolume(80);
g_snd.envirsound(true);
g_snd.bgsound(false);
cout << "---------------" << endl;
DuFacadePattern::GoldChatVoice& g_cv = DuFacadePattern::GoldChatVoice::getInstance();
g_cv.chatvolume(70);
g_cv.micsens(65);
/**/
DuFacadePattern::GoldConffacade& g_cffde = DuFacadePattern::GoldConffacade::getInstance();
cout << "低配置电脑,调用LowConfComputer接口" << endl;
g_cffde.LowConfComputer();
cout << "------------------" << endl;
cout << "高配置电脑,调用HighConfComputer接口" << endl;
g_cffde.HighConfComputer();
}
}
调用:
/*****************************************************************//**
* \file ConsoleDuFacadePattern.cpp
* \brief Facade Pattern 外观模式
* 涂聚文 Geovin Du Visual Studio 2022 edit.
* \author geovindu
* \date 20 May 2023
*********************************************************************/
// ConsoleDuFacadePattern.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#define _UNICODE
#include <iostream>
#include "GeovinDu.h"
using namespace DuFacadePattern;
int main()
{
std::cout << "Hello World!!Programa Olá Mundo!涂聚文 Geovin Du\n";
GeovinDu geovin;
geovin.displayFacade();
system("pause");
return 0;
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
#define UNICODE
输出:
Hello World!!Programa Olá Mundo!涂聚文 Geovin Du 图形->是否全屏显示->0 图形->是否开启特效->1 图形->分辨率设置选项->2 图形->是否开启抗锯齿->0 --------------- 声音->音量大小为->80 声音->是否开启环境音效->1 声音->是否开启背景声音->0 --------------- 语音聊天->聊天音量为->70 语音聊天->麦克风灵敏度为->65 低配置电脑,调用LowConfComputer接口 图形->是否全屏显示->1 图形->是否开启特效->0 图形->分辨率设置选项->2 图形->是否开启抗锯齿->0 声音->是否开启背景声音->0 声音->是否开启环境音效->0 声音->是否开启表情声音->0 声音->音量大小为->15 语音聊天->麦克风音量大小为->20 语音聊天->麦克风灵敏度为->50 语音聊天->聊天音量为->60 ------------------ 高配置电脑,调用HighConfComputer接口 图形->是否全屏显示->0 图形->是否开启特效->1 图形->分辨率设置选项->0 图形->是否开启抗锯齿->1 声音->是否开启背景声音->1 声音->是否开启环境音效->1 声音->是否开启表情声音->1 声音->音量大小为->50 语音聊天->麦克风音量大小为->100 语音聊天->麦克风灵敏度为->100 语音聊天->聊天音量为->100 请按任意键继续. . .

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
浙公网安备 33010602011771号