Lesson 0: Why Organize Code Into Objects At All?
You already know how to write functions, variables, and loops. But a growing procedural program tends to scatter: variables like customer_name, customer_balance, and customer_history show up in several different places in the code, and separate functions like calculate_discount() and print_receipt()
When every fact about a 'customer' is scattered across dozens of separate variables and functions, it's easy to miss one copy when something changes. OOP says: keep everything related to a customer — data and actions — together, in one place.
- procedural duplication
- A situation where the same data or business logic appears as separate copies in different places in the code.
- scattered state
- Data belonging to the same real-world 'thing' (e.g. a customer), but stored in separate, unbundled variables.
- single source of truth
- One unambiguous definition of what a given 'thing' is and does, referred to by every part of the program.
- bundling data and behavior
- The core OOP principle of grouping a thing's data together with the operations it can perform, in one place.