Last active
February 20, 2020 14:54
-
-
Save SomberNight/5c636a88e951ad4d403b7646d8ac92f0 to your computer and use it in GitHub Desktop.
Python3 interfaces plaything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABC, abstractmethod | |
class InterfaceA(ABC): | |
@abstractmethod | |
def method_a(self) -> None: ... | |
class InterfaceB(ABC): | |
@abstractmethod | |
def method_b(self) -> None: ... | |
class InterfaceAB(InterfaceA, InterfaceB): pass | |
class ClassA(InterfaceA): | |
def method_a(self) -> None: | |
print("a") | |
class ClassB(InterfaceB): | |
def method_b(self: 'InterfaceAB') -> None: | |
print("b") | |
self.method_a() | |
class AB(ClassA, ClassB): pass | |
ab = AB() | |
ab.method_b() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment