zoukankan      html  css  js  c++  java
  • 第12章外观模式

    一 概念

    • 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。

    二 UML图

    三 C++代码实现

    #include "pch.h"
    #include <iostream>
    using namespace std;
    
    //四个子系统的类
    class SubSystemOne
    {
    public:
    	void MethodOne()
    	{
    		cout << "子系统方法一" << endl;
    	}
    };
    
    class SubSystemTwo
    {
    public:
    	void MethodTwo()
    	{
    		cout << "子系统方法二" << endl;
    	}
    };
    
    class SubSystemThree
    {
    public:
    	void MethodThree()
    	{
    		cout << "子系统方法三" << endl;
    	}
    };
    
    class SubSystemFour
    {
    public:
    	void MethodFour()
    	{
    		cout << "子系统方法四" << endl;
    	}
    };
    
    //外观类
    class Facade
    {
    public:
    	Facade()
    	{
    		one = new SubSystemOne;
    		two = new SubSystemTwo;
    		three = new SubSystemThree;
    		four = new SubSystemFour;
    	}
    	~Facade()
    	{
    		delete one;
    		delete two;
    		delete three;
    		delete four;
    	}
    	void MathodA()
    	{
    		cout << "方法组A()----" << endl;
    		one->MethodOne();
    		two->MethodTwo();
    		four->MethodFour();
    	}
    	void MathodB()
    	{
    		cout << "方法组B()----" << endl;
    		two->MethodTwo();
    		three->MethodThree();
    	}
    private:
    	SubSystemOne* one;
    	SubSystemTwo* two;
    	SubSystemThree* three;
    	SubSystemFour* four;
    };
    int main()
    {
    	Facade* facade = new Facade;
    	facade->MathodA();
    	facade->MathodB();
    
    	delete facade;
    	
    	return 0;
    }
    
    
  • 相关阅读:
    9、 docker容器数据卷
    第十八章 MySQL数据库优化
    第十七章 MySQL的VIP漂移和Atlas
    第十六章 MHA高可用(续)
    第一章 shell基础
    第十五章 MHA高可用
    第十四章 MySQL的各种主从
    第十三章 MySQL的主从复制
    第十二章 MySQL的恢复与备份
    第十一章 MySQL日志详解
  • 原文地址:https://www.cnblogs.com/Manual-Linux/p/11127350.html
Copyright © 2011-2022 走看看