Skip to content

Latest commit

History

History
33 lines (25 loc) 路 724 Bytes

File metadata and controls

33 lines (25 loc) 路 724 Bytes

##馃崿 Virtual Proxy

The proxy pattern is used to provide a surrogate or placeholder object, which references an underlying object. Virtual proxy is used for loading object on demand.

Example:

protocol HEVSuitMedicalAid {
    func administerMorphine() -> String
}

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

class HEVSuitHumanInterface : HEVSuitMedicalAid {
    lazy private var physicalSuit: HEVSuit = HEVSuit()

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

Usage:

let humanInterface = HEVSuitHumanInterface()
humanInterface.administerMorphine()