Skip to main content
1 of 3
CaTs
  • 197
  • 3

Adding more methods to an interface is not always the solution to the Law of Demeter. You do not need to distinguish these cases, you need to find a different way to resolve them.

Take your second example:

print(account.user().fullName())
print(account.user().socialSecurityNumber())

Does your caller here need to interact with an account at all? Remove account as a dependency and provide user as an argument instead:

print(user().fullname())
print(user().socialSecurityNumber())
CaTs
  • 197
  • 3