Object-Oriented Programming
Prof. Seungtaek Choi
Recap
Recap: Why OOP?
Recap: Class (Class? Object?)
Recap: FourCal API (4)
How can we prevent invalid state at creation time?
Recap: FourCal API (4)
It’s safer than .setdata() as instances are valid immediately.
Recap: Why __init__ Matters
Recap: Inheritance (Extending Behavior)
Recap: Method Overriding (Changing Behavior)
Recap: Class Variables vs. Instance Variables (2)
Recap: Class Variables vs. Instance Variables (3)
Recap: Glossary
Recap: Package
Today
OOP Basics
Type Hints
Type Hints - Collections, Optional, and Unions
Duck Typing: Behavior over Types
Safer Duck Typing (EAFP: try/except)
When to Prefer ABC (Explicit Interface)
EAFP vs. LBYL
Access Control (Python Way)
Practical Access Control
When Private Makes Sense
Imports that Matter to OOP
Imports that Matter to OOP (Practical)
__new__ vs. __init__
__del__ (Destructor): Use with Care
Object Lifecycle (Creation 🡪 Init 🡪 (Optional) Destruct)
super(): Why & What
super(): in __init__ (Chaining Init)
Override + super(): Extend, Don’t Replace
Common Pitfall: Forgetting super() in __init__
super() Chains (Mental Model)
Next