What is an abstract class?

A Python programmer recently asked me what an abstract class is, given the other explanations I found seemed to imply that you already really knew what one was – I decided to come up with my own:

An abstract class is a class that you cannot instantiate, they implement some base methods and guarantee that child classes will implement others.

In the animal world, a Mammal would be an abstract class – it defines that all Mammals have fur, teeth and give live birth – the specifics of which vary from species to species.   You can’t create a Mammal, but you can create a Dog which extends the Mammal – has teeth, fur and the specific dog class can describe exactly how the live birth proceeds.

The Mammal class might also extend the Vertebrate class which defines things like bones, central nervous system and so on.

This entry was posted in Object oriented programming and tagged , , , . Bookmark the permalink.

Leave a Reply

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