QamoosTech
Programming FundamentalsObject-oriented programmingIntermediatePython

Abstract Class

PronunciationAB-strakt KLAS

Definition

An abstract class is a base class that cannot be created directly. It defines methods that every subclass must implement.

Where you hear it

In object-oriented design, Python's abc module, Java, and code reviews about shared behaviour.

Examples

  • The base PaymentMethod is abstract; each concrete class implements charge().
  • You cannot instantiate an abstract class.
  • The abstract Shape class requires every subclass to implement area().

Common mistake

Creating an abstract base for one subclass. Wait until at least two real cases share behaviour.

Don't confuse with

An interface, which lists methods only, with no shared code. An abstract class can include working code too.

Say it at work

  • In a meeting or chatMake the base class abstract so nobody instantiates it by mistake.
  • In an email or ticketEvery subclass must override the abstract method.