Python has come up with a module which provides the helper class for defining Abstract Base Classes (ABC) and that module name is abc.
The ABC allows you to mark classes as abstract ones and distinguish which methods of the base abstract class are abstract. A method becomes abstract by being decorated with an @abstractmethod
decorator.
To start with ABC you should:
- import the
abc
module; - make your base class inherit the helper class
ABC
, which is delivered by theabc
module; - decorate abstract methods with
@abstractmethod
, which is delivered by theabc
module.
When you run the code, the output doesn’t surprise anyone:
Welcome to Green Field!
output
So far everything works fine, so let's play with the code a little.