class Controller: def __init__(self): self.service = Service() #인스턴스 변수 선언 @staticmethod #self를 없애고 해당 어노테이션을 달면 스테틱 메소드가 된다. def print_menu(): print('1. 연락처 입력: ') print('2. 연락처 출력: ') print('3. 연락처 삭제: ') print('0. 종료 ') return input('메뉴 선택 \n') def run(self): contacts = [] while 1: menu = self.print_menu() print('메뉴 : %s' % menu) if menu == '1': name = input('이름 : \n') phone = input('전화번호 : \n') email = input('이메일 : \n') addr = input('주소 \n') t = self.service.set_contact(name, phone, email, addr) contacts.append(t) elif menu == '2': print(self.service.get_contacts(contacts)) elif menu == '3': name = input('삭제할 이름 ') self.service.del_contact(contacts, name) elif menu == '0': print('시스템 종료 : ') break
class Controller: def __init__(self): self.service = Service() def register(self, name, phone, email, addr): entity = Entity() entity.name = name entity.phone = phone entity.email = email entity.addr = addr self.service.add_contact(entity) def list(self): return self.service.get_contacts() def remove(self, name): self.service.del_contact(name)
class Controller: def __init__(self): self._service = Service() def register(self, name, phone, email, addr): model = Model() model.name = name # setter 이고 _ 제거됌 model.phone = phone model.email = email model.addr = addr self._service.add_contact(model) print(model) def search(self, name) -> object: self._service.get_contact(name) def list(self): return self._service.get_contacts() def remove(self, name): self._service.del_contact(name)