in

Abstraction in Python

In this article, we will learn about Abstraction in Python.

Start learning Python from scratch for Free.

Abstraction

Abstraction in Python
Abstraction in Python

Sometimes we want that our class should not be instantiated. Since we are the creator of the class, we know it is abstract in nature and we won’t create an instance for it. But how can another programmer know about it? How can we ensure that some other developer does not end up creating an object of such an abstract class?

So for removing this error we have have to declare a class as abstract class.

Abstract class

We can programmatically declare a class as abstract class.

An Abstract class is a class that can not be instantiated.

python abstract class

Abstract class should never be instantiated, the only way we can use the abstract class is to inherit that class to another class.

Summery

  • Usually the parent class is an abstract class.
  • Abstract classes should not be instantiated.
  • If a class has an abstract method, then the class cannot be instantiated.
  • Abstract classes are meant to be inherited.
  • The child class must implement/override all the abstract methods of the parent class. Else the child class cannot be instantiated.

What do you think?

Written by Nishant Tyagi

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

0

Add a button to the WordPress header

Polymorphism and Super Class in Python Inheritance – Python Oops