Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Body {
- case head
- case hand
- case leg
- }
- protocol DoctorDelegate {
- var history: [Body: String] { get set }
- func heal(name: String, symptom: Body, temperature: Int)
- }
- protocol PatientProtocol {
- var name: String { get set }
- var temperature: Int { get set }
- var symptom: Body { get set }
- var doctor: DoctorDelegate? { get set }
- init(name: String, symptom: Body, temperature: Int, doctor: DoctorDelegate)
- }
- class Doctor: DoctorDelegate {
- var history: [Body: String] = [:]
- func heal(name: String, symptom: Body, temperature: Int){
- history[symptom] = name
- print("I healed \(name). \(symptom) and temperature \(temperature)")
- }
- }
- class BadDoctor: DoctorDelegate {
- var history: [Body: String] = [:]
- func heal(name: String, symptom: Body, temperature: Int) {
- print("Vdrug samo proidet, dergis', \(name)")
- }
- }
- class Patient: PatientProtocol {
- var name: String
- var temperature: Int
- var symptom: Body
- var doctor: DoctorDelegate?
- func callDoctor(){
- doctor?.heal(name: name, symptom: symptom, temperature: temperature)
- }
- required init(name: String, symptom: Body, temperature: Int, doctor: DoctorDelegate) {
- self.name = name
- self.temperature = temperature
- self.symptom = symptom
- self.doctor = doctor
- }
- }
- var doctor = Doctor()
- var badDoctor = BadDoctor()
- var mark = Patient(name: "Mark", symptom: Body.head, temperature: 38, doctor: doctor)
- var alex = Patient(name: "Alex", symptom: Body.leg, temperature: 37, doctor: badDoctor)
- var peter = Patient(name: "Peter", symptom: Body.hand, temperature: 39, doctor: doctor)
- var patients = [mark, alex, peter]
- for patient in patients {
- patient.callDoctor()
- }
- print(doctor.history)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement