cpp: Facade Pattern

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/*****************************************************************//**
 * \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();
             
 
    }
 
}

  

调用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*****************************************************************//**
 * \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

  

输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
请按任意键继续. . .

  

 

posted @   ®Geovin Du Dream Park™  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2013-05-20 Csharp: jmail組件發送郵件
2011-05-20 Repeater嵌套DataList
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示