Pythonクラス(抽象クラス)
クラス-抽象クラス
""" 추상 클래스는 메서드 목록만 가진 클래스이며 상속받는 클래스에서 메서드 구현을 강제하기 위해 사용함
추상 클래스는 인스턴스로 만들 수 없음.
추상 클래스는 인스턴스로 만들기 위한 클래스가 아니고, 오로지 상속만을 위한 클래스임.
자식 클래스에서 반드시 구현해야할 메서드를 정해줄 때 사용함 """
from abc import * # adc 임포트해와야 추상메서드 활용 가능
class StudentBase(metaclass=ABCMeta): # 이건그냥 규칙임 따라야됌
@abstractmethod # @abstractmethod 를 붙여서 추상 메서드 지정
def study(self):
pass # 추상 메서드는 호출할 일이 없으므로 빈 메서드로 만듦
@abstractmethod # @abstractmethod 를 붙여서 추상 메서드 지정
def go_to_school(self):
pass
class Student(StudentBase):
def study(self):
print('공부하기')
def go_to_school(self):
print('학교가기')
james = Student()
james.study()
james.go_to_school()
Reference
この問題について(Pythonクラス(抽象クラス)), 我々は、より多くの情報をここで見つけました https://velog.io/@tkjung/파이썬-클래스추상-클래스テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol