Skip to content
UPEEC

Advanced Object-Oriented Python

The OOP principles and Python-specific tools: polymorphism, encapsulation, properties, descriptors, ABCs and metaclasses.

Intermediate
Comments 0

Python's OOP is flexible: "duck typing" means what matters is what an object can do, not what it inherits from.

Sub-topics (11)

Polymorphism

Different classes respond to the same method call in their own way.

Easy♥ 0🔖 0💬 0

Encapsulation

Keep an object's internal state behind methods; Python uses naming conventions rather than enforced privacy.

Easy♥ 0🔖 0💬 0

Abstraction

Expose what an object does and hide how it does it.

Easy♥ 0🔖 0💬 0

Method Overriding

A subclass replaces a parent method with its own version, optionally calling the parent via super().

Easy♥ 0🔖 0💬 0

Method Overloading Patterns

Python has no signature-based overloading; use default arguments, *args or functools.singledispatch instead.

Intermediate♥ 0🔖 0💬 0

Properties

@property turns a method into an attribute-like getter, with optional setter validation.

Easy♥ 0🔖 0💬 0

Descriptors

Objects that control attribute access on another class via __get__, __set__ and __delete__ — the machinery behind properties and methods.

Advanced♥ 0🔖 0💬 0

Abstract Base Classes

abc.ABC and @abstractmethod define interfaces that subclasses must implement.

Intermediate♥ 0🔖 0💬 0

Multiple Inheritance and the MRO

A class can inherit from several bases; Python resolves methods with the C3 Method Resolution Order.

Intermediate♥ 0🔖 0💬 0

Metaclasses

The class of a class: metaclasses customise how classes themselves are created.

Expert♥ 0🔖 0💬 0

Dataclasses

@dataclass writes __init__, __repr__ and __eq__ for classes that mainly hold data.

Easy♥ 0🔖 0💬 0

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.