Created
August 16, 2020 11:22
-
-
Save paulfranco/9fdfcdd0684e1bab61b26a1c83f60298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// protocols and delegates | |
// | |
// Created by Paul Franco on 8/16/20. | |
// | |
protocol EmergencyMedicalTechnician { | |
func performCPR() | |
} | |
class EmergencyCallHandler { | |
var delegate: EmergencyMedicalTechnician? | |
func takeEmergencyCall() { | |
// Emergency Call Procedures | |
// Answer Call | |
print("Answer Call") | |
// Get Emergency details | |
print("Get Emergency details") | |
// Other procedures | |
} | |
func dispatchMedicalEmergency() { | |
delegate?.performCPR() | |
} | |
} | |
struct Paramedic: EmergencyMedicalTechnician { | |
init(handler: EmergencyCallHandler) { | |
handler.delegate = self | |
} | |
func performCPR() { | |
print("Paramedic performs CPR by giving chest compressions") | |
} | |
} | |
struct Nurse: EmergencyMedicalTechnician { | |
init(handler: EmergencyCallHandler) { | |
handler.delegate = self | |
} | |
func performCPR() { | |
print("Paramedic performs CPR by giving chest compressions") | |
} | |
func drawBlood() { | |
print("drawing blood") | |
} | |
} | |
let John = EmergencyCallHandler() | |
let Susan = Nurse(handler: John) | |
John.takeEmergencyCall() | |
John.dispatchMedicalEmergency() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment