0

What is the right way to make every class that inherits from the superclass have the same functionality in python ?

The superclass doesn't implement anything, it just defines the needed functionality for the child classes to be used by functions in some app.

What is the right way to implement such a thing in Python?

  • Please check the below post for your problem. [How do I implement interfaces in python?](https://stackoverflow.com/questions/2124190/how-do-i-implement-interfaces-in-python) – freddylauhk Dec 14 '21 at 06:30
  • Python is a Duck Typed language. If the required methods are implemented in a class, it doesn't even matter if the class inherits from the base class or not. – Mark Ransom Dec 14 '21 at 06:42
  • @MarkRansom registering to an ABC without inheriting is a very powerful feature. So as `__subclasshook__` and the typing protocols. – Bharel Dec 14 '21 at 07:09

1 Answers1

1

Using Abstract Base Classes is the advised solution.

You're welcome to read the abc module, it is very informative.

For some built-in examples, you can see collections.abc.

Bharel
  • 23,672
  • 5
  • 40
  • 80