4개의 클래스를 만든다.
Person
Doctor
Patient
Appointment
Doctor와 Patient 클래스는 Person이라는 클래스를 상속받을거고 이를 바탕으로 환자와 의사가 약속을 잡는 Appointment에서는 doctor와 patient를 속성으로 받을거다.
#비대면진료 시스템 만들어보기..... (오후 1)
# 사람 class >> 의사, 환자정보 업뎃
# 진료 일정잡는거
class Person:
def __init__(self, name, age): #person은 이름과 나이만 받는다.
self.name = name
self.age = age
class Doctor(Person): #의사분들이 확인해야할 진료일정 수
total_appointments = 0
def __init__(self, name, age, hospital):
super().__init__(name, age) #상속받은 Person의 init 메소드 실행.
self.hospital = hospital
self._appointments = 0
@classmethod #위에 있는 클래스의 변수나 함수에 접근하기 위해서 사용.
def update_total_appointments(cls):
cls.total_appointments += 1
def patient_meeting(self):
self._appointments += 1
class Patient(Person):
def __init__(self, name, age, hospital): #patient도 hospital정보 따로받기
super().__init__(name, age)
class Appointment:
def __init__(self, doctor, patient):
self.doctor = doctor
self.patient = patient
def done(self): #진료 끝났을 때 done실행.
self.doctor._appointments += 1
self.doctor.update_total_appointments()
patient = Patient('Jane', 60, '아주대병원')
doctor = Doctor('이국종', 50, '아주대병원')
이국종교수님과 아주대병원에서 Jane이 진료를 받는다고 가정.
appointment = Appointment(doctor, patient)
appointment.done()
마지막으로 done 실행해주면 의사 선상님의 total_appointment가 업데이트된다.