Conceptual
Login

Python Protocols vs ABCs: Runtime Typing and Inheritance Differences

Abstract Base Classes (ABCs) and Protocols are two mechanisms in Python's type system for defining interfaces: ABCs rely on nominal typing, requiring explicit inheritance and enforcing method implementation at instantiation time, while Protocols rely on structural typing (duck typing), where conformance is determined by an object's shape (its methods/attributes) rather than its class hierarchy. This distinction reflects a broader software design tradeoff between explicit, inheritance-based interface contracts and implicit, structural interface conformance, both of which serve the object-oriented design principle of dependency inversion by decoupling code from concrete implementations. The domain is Python's typing and object-oriented design system, specifically interface abstraction within static/runtime type checking.