Abstract Classes: A Key Concept in Python’s Object-Oriented Toolkit

Saeed Mohajeryami, PhD
Tech & Data Hub
Published in
9 min readFeb 13, 2023

--

In this article, I want to dig into the basics of abstract classes in Python and explore what they are, why they’re useful, and how they differ from other object-oriented programming (OOP) constructs.

First of all, let’s define what I mean by an abstract class. Simply put, an abstract class is a blueprint for creating objects (or a class that can’t be instantiated on its own). It serves as a base class that defines common properties and methods that are shared among its subclasses. However, an abstract class can’t be used on its own; instead, it’s meant to be inherited and extended by concrete classes that provide implementation details.

So why bother with abstract classes in the first place? There are several key benefits to using abstract classes in your code:

  • They provide a common interface for subclasses. This means that if you have a base class that defines a set of methods and properties, all subclasses that inherit from it are expected to have those same methods and properties. This makes it easier to write reusable code that’s consistent across different classes. It’s like a check and balance. You ask your children that if they want to inherit from you, they must overwrite certain methods.
  • They enforce a minimum set of methods and properties. By…

--

--

Saeed Mohajeryami, PhD
Tech & Data Hub

Senior Data Engineer @Ascertain, New York, New York. SUBSCRIBE to my free newsletter https://techleadcuriosity.substack.com/