Posts

Showing posts from February, 2026

Abstract class and Interface in python

Image
  n Python, there is no official   interface   keyword like in Java or C#. Instead, we use   Abstract Base Classes (ABCs)   via the   abc   module to create both abstract classes and "formal interfaces".   Real Python  +3 1. Abstract Class vs. Interface in Python Abstract Class:  A "blueprint" that cannot be instantiated and can contain both implemented (concrete) methods and unimplemented (abstract) methods. Interface:  In Python, this is essentially an abstract class where  all  methods are marked with  @abstractmethod  and contain no implementation (only  pass ).   GeeksforGeeks  +3 2. What Can Be Included Feature   Abstract Class Interface (ABC) Description Abstract Method Yes Yes Defined using the  @abstractmethod  decorator; must be overridden by subclasses. Constructor  ( __init__ ) Yes No (usually) Can hold shared initialization logic. While technically possible in inter...