One Dot per Line
Based on the Law of Demeter β don't reach through an object's internals. Ask the object to do the work instead of navigating its parts.
Why this matters
Every dot after the first in a chain like order.customer.address.city is a hidden coupling. Your code now knows about Order, Customer, Address, and City β four classes instead of one. Rename any field in any of those classes and this single line breaks. The Law of Demeter says: talk only to your immediate neighbors. Don't navigate through objects to reach what you need β ask the closest object to do the work for you.
Code Challenge
Study the messy code, try to refactor it, then reveal the clean version.
π‘Key takeaway
Count the dots. Each dot after the first is a dependency on something you shouldn't know exists. Move the logic into the object that owns the data β one dot per line keeps coupling local and refactoring safe.
π§ Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it β it helps us fix it fast.
Hint: Count the dots. Each dot after the first is a dependency on something you shouldn't know exists.
β Your version