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
PaymentMethodis abstract; each concrete class implementscharge().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 chat
Make the base class abstract so nobody instantiates it by mistake.
- In an email or ticket
Every subclass must override the abstract method.
Keep exploring
More in Programming Fundamentals