/*****************************************************************//** * \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 請按任意鍵繼續. . .