What is the difference between an interface and an abstract class?medium
Answer
An interface defines a contract (method signatures) with no state. An abstract class can have state, concrete methods, and constructors - it is a partial implementation meant to be extended.
Explanation
Use an interface when unrelated classes need to fulfil a common contract (e.g., both a Dog and a Robot implement Moveable ). Use an abstract class when you want to share code among closely related classes and enforce some structure. Many languages allow multiple interface implementation but only single class inheritance, making interfaces more flexible for composition.
Follow-upHow does Python's ABC module implement abstract classes?