Skip to content

Instantly share code, notes, and snippets.

@skatesham
Last active October 23, 2020 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skatesham/ef3084d8d23e6fa529ab0126f353cb84 to your computer and use it in GitHub Desktop.
Save skatesham/ef3084d8d23e6fa529ab0126f353cb84 to your computer and use it in GitHub Desktop.
Polymorphism and Abstract Method Overriding implementing an Interface
from abc import ABC, abstractmethod
def main():
for obj in (LocalFinder(), ExternalFinder()):
obj.explore()
obj.comming_back()
class FinderInterface(ABC):
@abstractmethod
def explore(self) -> str:
"""Exploring OOP on Python"""
raise NotImplementedError
@abstractmethod
def comming_back(self) -> str:
"""Comming back"""
raise NotImplementedError
class LocalFinder(FinderInterface):
def explore(self):
print("Exploring just local")
def comming_back(self):
print("Back to Local")
class ExternalFinder(FinderInterface):
def explore(self):
print("Exploring from external")
def comming_back(self):
print("Back to Abroad")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment