Interview practice question
Long chains of method calls
Backend Engineering · OOP and Design Patterns · Intermediate
A reviewer flags code like invoice.getOrder().getCustomer().getAccount().getManager().getEmail(). What is the concern, and how would you refactor?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Law of Demeter violation.
- Couples to many classes' structure.
- Null risks along chain.
- Ask the nearest object for what you need.
- Or pass the needed value directly.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.