Chapter 6: OOP¶
This chapter provides a comprehensive guide to object-oriented programming in Python, from foundational concepts through advanced topics like descriptors, metaclasses, dataclasses, and design patterns.
6.1 OOP Foundations¶
6.2 Attributes and Methods¶
6.3 Four Pillars of OOP¶
6.4 Advanced Inheritance¶
6.5 Composition and Aggregation¶
6.6 Dunder Basics¶
- Introduction
- Arithmetic Operators
- Comparison Operators
- Object Lifecycle
- String Representation
- Magic Methods Quick Reference
- Magic Methods Exercises
6.7 Dunder Advanced¶
6.8 Properties¶
- Property Decorator
- Getter Setter Deleter
- Cached Properties
- Read-Only Properties
- Properties as Descriptors
6.9 Descriptor Protocol¶
- Descriptor Introduction
- __get__ __set__ __delete__
- Data vs Non-Data Descriptors
- Descriptor Use Cases
- Attribute Access Lookup
6.10 Dunder Attribute Hooks¶
6.11 Dynamic Attribute Access¶
6.12 dataclasses¶
- dataclasses Module
- field() Function
- __post_init__ Method
- Frozen Dataclasses
- Dataclass Inheritance
- slots and kw_only
- Dataclass vs NamedTuple vs attrs
- Practical Patterns
6.13 Enumerations¶
- Enum Basics
- Enum Members and Values
- IntEnum and StrEnum
- Flag and IntFlag
- auto() Function
- Enum Methods and Customization
- Enum Practical Patterns