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.
为子系统中的一组接口提供一个一致的界面, 外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
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();
}
}