abstract class

About_work·2023년 2월 20일
0

python 기초

목록 보기
20/56

추상 클래스란?

  • 추상클래스란 미구현 추상메소드를 한개 이상 가지며, 자식클래스에서 해당 추상 메소드를 반드시 구현하도록 강제
  • 상속받은 클래스는 추상메소드를 구현하지 않아도, import할 때까지 에러는 발생하지 않으나 객체를 생성할 시 에러가 발생
from abc import *

class Base(ABC):
    @abstractmethod
    def run(self):
        print('haha')

class Child(Base):
    def run(self):
        print('haha')

혹은

from abc import *

class Base(metaclass-ABCmeta):
    @abstractmethod
    def run(self):
        print('haha')

class Child(Base):
    def run(self):
        print('haha')
profile
새로운 것이 들어오면 이미 있는 것과 충돌을 시도하라.

0개의 댓글