---
title: "Law of Demeter"
author: "llystar"
date: "2013-09-05T17:04:39Z"
tags: []
categories: ["编程语言"]
slug: "law-of-demeter"
draft: false
lastmod: "2013-09-05T17:04:39Z"
id: 1936985
url: "https://llystar.iteye.com/blog/1936985"
---

Researchers have formulated a rule called the “Law of  Demeter” (Lieberherr and Holland 1989) which essentially states that Object A can call any of its own routines. If Object A instantiates an Object B, it can call  
 any of Object B’s routines. But it should avoid calling routines on objects provided by Object B. In the account example above, that means  
      account.ContactPerson() is OK, but  
      account.ContactPerson().DaytimeContactInfo() is not.