Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. enum Body {
  2. case head
  3. case hand
  4. case leg
  5. }
  6.  
  7. protocol DoctorDelegate {
  8. var history: [Body: String] { get set }
  9. func heal(name: String, symptom: Body, temperature: Int)
  10. }
  11.  
  12. protocol PatientProtocol {
  13. var name: String { get set }
  14. var temperature: Int { get set }
  15. var symptom: Body { get set }
  16. var doctor: DoctorDelegate? { get set }
  17. init(name: String, symptom: Body, temperature: Int, doctor: DoctorDelegate)
  18. }
  19.  
  20. class Doctor: DoctorDelegate {
  21. var history: [Body: String] = [:]
  22. func heal(name: String, symptom: Body, temperature: Int){
  23. history[symptom] = name
  24. print("I healed \(name). \(symptom) and temperature \(temperature)")
  25. }
  26.  
  27. }
  28.  
  29. class BadDoctor: DoctorDelegate {
  30. var history: [Body: String] = [:]
  31. func heal(name: String, symptom: Body, temperature: Int) {
  32. print("Vdrug samo proidet, dergis', \(name)")
  33. }
  34. }
  35.  
  36. class Patient: PatientProtocol {
  37. var name: String
  38. var temperature: Int
  39. var symptom: Body
  40. var doctor: DoctorDelegate?
  41.  
  42. func callDoctor(){
  43. doctor?.heal(name: name, symptom: symptom, temperature: temperature)
  44. }
  45.  
  46. required init(name: String, symptom: Body, temperature: Int, doctor: DoctorDelegate) {
  47. self.name = name
  48. self.temperature = temperature
  49. self.symptom = symptom
  50. self.doctor = doctor
  51. }
  52. }
  53.  
  54. var doctor = Doctor()
  55. var badDoctor = BadDoctor()
  56. var mark = Patient(name: "Mark", symptom: Body.head, temperature: 38, doctor: doctor)
  57. var alex = Patient(name: "Alex", symptom: Body.leg, temperature: 37, doctor: badDoctor)
  58. var peter = Patient(name: "Peter", symptom: Body.hand, temperature: 39, doctor: doctor)
  59.  
  60. var patients = [mark, alex, peter]
  61.  
  62. for patient in patients {
  63. patient.callDoctor()
  64. }
  65.  
  66. print(doctor.history)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement