? 虚拟代理(结构型模式)

在代理模式中,创建一个类代表另一个底层类的功能。
虚拟代理用于对象的需时加载。

示例:

protocol HEVSuitMedicalAid {
    func administerMorphine() -> String
}

final class HEVSuit: HEVSuitMedicalAid {
    func administerMorphine() -> String {
        return "Morphine administered."
    }
}

final class HEVSuitHumanInterface: HEVSuitMedicalAid {

    lazy private var physicalSuit: HEVSuit = HEVSuit()

    func administerMorphine() -> String {
        return physicalSuit.administerMorphine()
    }
}

用法

let humanInterface = HEVSuitHumanInterface()
humanInterface.administerMorphine()

Made with in Shangrao,China By 老雷

Copyright © devler.cn 1987 - Present

赣ICP备19009883号-1