Skip to main content

Sign in to CleanKata

Track your progress, earn XP, and unlock every lesson.

By signing in you agree to our Terms of Use and Privacy Policy.

Object Calisthenics70 XP7 min

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