设计模式--结构型模式--外观模式

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;
//Structural Patterns--Facade
//结构型模式--外观模式

//Facade(外观):模式的核心,被 Client 调用,知晓相关子系统的功能和责任。在正常情况下,它将所有从 Client 发来的请求委派到相应的子系统去,让子系统处理。
//SubSystem(子系统):可以同时有一个或者多个子系统,子系统可以是一个单独的类或类的集合。每个子系统都可以被 Client 直接调用,或者被 Facade 调用,
//    它处理由 Facade 传过来的请求。子系统并不知道 Facade 的存在,对于子系统而言,Facade 仅仅是另外一个 Client 而已。

class Cpu
{
public:
    void ProductCpu(){cout << "Product Cpu." << endl;}
};
class Ram
{
public:
    void ProductRam(){cout << "Product Ram." << endl;}
};
class Graphics
{
public:
    void ProductGraphics(){cout << "Product CpuGraphics." << endl;}
};
class Computer
{
public:
    void ProductComputer()
    {
        Cpu c;
        c.ProductCpu();

        Ram r;
        r.ProductRam();

        Graphics g;
        g.ProductGraphics();
    }
};

void dpFacadeTestMain()
{
    Computer computer;
    computer.ProductComputer();

    Cpu c;
    c.ProductCpu();

    return;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值