• Category: structural
  • Type: object
  • Motivation: provide a simplified interface to larger body of code

diagram

do {
    let computer = Computer()
    computer.start()
}
struct CPU
{
    func freeze()
    {
        print("freeze")
    }

    func jump()
    {
        print("jump to...")
    }

    func execute()
    {
        print("execute")
    }
}

struct HardDrive
{
    func read() -> String
    {
        print("read from hard drive")
        return "data"
    }
}

struct Memory
{
    func load(data: String)
    {
        print("load \(data) into memory")
    }
}
class Computer
{
    let cpu = CPU()
    let memory = Memory()
    let hardDrive = HardDrive()

    func start()
    {
        cpu.freeze()
        memory.load(data: hardDrive.read())
        cpu.jump()
        cpu.execute()
    }
}