Law of Demeter (Principle of Least Knowledge)

Dated Sep 11, 2026; last modified on Fri, 11 Sep 2026

Code like order.GetCustomer().getAddress().getZipCode() violates the Law of Demeter. This code is coupled to the internal structure of three different objects. Instead, have Order.getCustomerZipCode() that handles the navigation internally.

I don’t fully follow. Doesn’t Order.getCustomerZipCode() have _customer.GetAddress().GetZipCode(), and therefore we’re back where we were but coupled to \(N-1\) objects?

Method chaining itself is not the problem. Fluent interfaces like builder.setName("John").setAge(30).build() are fine because they return the same object type, e.g., PersonBuilder.

  1. Design Principles | Hello Interview Low Level Design. www.hellointerview.com . Accessed Sep 10, 2026.