前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >设计模式之外观模式

设计模式之外观模式

作者头像
beginor
发布2020-08-10 11:31:51
1930
发布2020-08-10 11:31:51
举报
文章被收录于专栏:张志敏的技术专栏

设计模式之外观模式

结构

说明

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

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

适用条件

  • 为一个比较复杂的子系统提供一个简单的接口;
  • 将客户程序与子系统的实现部分分离, 提高子系统的独立性和可移植性;
  • 简化子系统间的依赖关系。

实现

代码语言:javascript
复制
class Cpu {

   public void Freeze() {
   }

   public void Jump(long position) {
   }

   public void Execute() {
   }

}

class Memory {
   
   public void Load(long address, byte[] data) {
   }

}

class HardDrive {
   
   public byte[] Read(long address) {
      return new byte[0];
   }

}

class Computer {

   private readonly Cpu _cpu;
   private readonly Memory _memory;
   private readonly HardDrive _hardDrive;

   private const long BootAddress = 0;

   public Computer() {
      this._cpu = new Cpu();
      this._memory = new Memory();
      this._hardDrive = new HardDrive();
   }

   public void StartComputer() {
      this._cpu.Freeze();
      this._memory.Load(BootAddress, this._hardDrive.Read(    BootAddress));
      this._cpu.Execute();
   }
}

class Program {
   
   static void Main(string[] args) {
      var facade = new Computer();
      facade.StartComputer();
   }

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 设计模式之外观模式
    • 结构
      • 说明
        • 适用条件
          • 实现
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档