Stage 1 · Lesson 8 of 8
Pythonic OOP: dataclasses, Protocol and properties
Python has no private keyword. A leading underscore, such as _balance, tells other developers a name is internal, and @property lets you expose a read-only value with attribute syntax. write the , equality and printing for classes that mostly hold data, and frozen=True makes them .
For , typing.Protocol describes the methods a type needs, and a type checker such as mypy or Pyright verifies it without any . abc.ABC gives you abstract base classes when you want shared code. Python also has first-class functions, so a one-method class is often better as a plain function.
Common trapwriting Java-style Python, with getters, setters and a class for everything, when a function or a dataclass would be clearer.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking the Object Oriented Design Interview
Design Gurus · Intermediate · Subscription
Its opening chapters teach the four OOP ideas applied inside real designs, with UML and running code
- CourseFreeMIT 6.102: Software Construction
MIT · Intermediate
Free MIT readings: Abstract Data Types, Rep Invariants and Interfaces and Subtyping are this stage at university depth