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.
Law of Demeter
最新推荐文章于 2023-08-29 00:04:35 发布