Aurelio  Yost

Aurelio Yost

1625725320

Abstract Methods and Classes in Python Examples and Explanations

Abstrac clas is a kind of model for other classes to be defined. It is not designed to construct instances, but can be subclasses by regular classes. Abstract class is a blueprint for subclasses.

Abstract classes can define an interface, or methods that must be implemented by its subclasses. An abstract class is a class that contains one or more abstract methods.

If we are working on the team or if we designing a library that requires other members to contribute classes we might want to require that the developers implement certain methods.

If that is the basic interface that we would like other developers to implement, we can ask them su subclass or inherit from our classand we will want to declare our methods in such a way that defining
these methods is required in any subclass.

Abstract methods are the methods that generally don’t have any implementation, it is left to the sub classes to provide implementation for the abstract methods. Here note that in Python abstract method can have implementation in the abstract class too but the sub class inheriting that abstract class is still forced to override the abstract methods.

Table of Content:
0:26 - Abstract class in Python
0:58 - Abstract method in Python
1:23 - Important points about abstract class in Python
2:11 - Python abstract class example
2:43 - Python abstract class with abstract method implemented
3:14 - Not implementing all abstract methods
3:35 - Instantiating abstract class in Pyhton

Wishes!

  • Vytautas.

#python

Abstract Methods and Classes in Python  Examples and Explanations