Design Patterns · Middle · Question 21 of 75

What does the Law of Demeter say about order.customer.address.city.name?

Explanation

"Talk only to your friends": long chains tie code to the internals of many objects, and a change in any of them breaks the caller. The fix is a method or selector like getDeliveryCity(order).

Further reading

Problem with a question

Design Patterns · Middle · question 21

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz