Stay Hungry,Stay Foolish!

abc.abstractmethod + property

abc.abstractmethod + property

https://stackoverflow.com/questions/14671095/abc-abstractmethod-property

 

import abc

class FooBase(metaclass=abc.ABCMeta):

    @property
    @abc.abstractmethod
    def greet(self):
        """ must be implemented in order to instantiate """
        pass

    @property
    def greet_comparison(self):
        """ must be implemented in order to instantiate """
        return 'hello'

class Foo(FooBase):
    @property
    def greet(self):
        return 'hello'

abstract-class

https://codefather.tech/blog/python-abstract-class/

from abc import ABC, abstractmethod

class Aircraft(ABC):

    @abstractmethod
    def fly(self):
        pass

    @abstractmethod
    def land(self):
        print("All checks completed")

class Jet(Aircraft):

    def fly(self):
        print("My jet is flying")

    def land(self):
        super().land()
        print("My jet has landed")

 

posted @ 2023-12-11 22:26  lightsong  阅读(5)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel