From Brad_Appleton-GBDA001@aieg.mot.com Thu Oct 24 13:22:36 1996 From: Brad Appleton Subject: Re: (OTUG) Law of Demeter To: otug@rational.com (Object Technology user's group) Cc: lieber@ccs.neu.edu (Karl Lieberherr) Reply-To: Brad_Appleton-GBDA001@email.mot.com Organization: Motorola Automotive and Industrial Electronics Group Andreas_Helmer writes: > has someone of you ever heard about the "Law of Demeter" ? The name "Demeter" refers to the Demeter System and Tools being developed by Karl Lieberherr and friends at Northeastern Univeristy. The "Law of Demeter" refers to a paper that was published in IEEE Software in 1989. Lieberherr, Karl. J. and Holland, I. Assuring good style for object-oriented programs IEEE Software, September 1989, pp 38-48 I think they also had a paper along the same lines at OOPSLA'89 (give or take a year). There is also a "Law of Demeter" URL located at http://www.ccs.neu.edu/home/lieber/LoD.html which is reachable from the "Demeter Home Page". Basically, they came up with the following "Law of Demeter": A method "M" of an object "O" should invoke *only* the the methods of the following kinds of objects: 1. itself 2. its parameters 3. any objects it creates/instantiates 4. its direct component objects The basic idea is to avoid invoking methods of an object that is returned by another method. When you do this, you are making some structural assumptions about the container object that may be likely to change. The container may later need to be modified to contain a different number of the contained objects, or it may end up being changed to contain another object which contains the original component object. Thus using the Law of Demeter (abbreviated as "LoD") you instead ask the container to invoke a method on its elements and return the result. The details of how the container propgates the message to its elements are encapsulated by the containing object. A side-effect of this is that if you conform to LoD, while it may quite likely increase the maintainability and "adaptiveness" of your software system. you also end up having to write *lots* of little wrapper methods to propagate methods calls to its components (which can add noticeable time and space overhead). The Demeter system and tools is about "Adaptive" programming, which is an addition to OOP that attempts wait to bind algorithms to data-structures until as late as possible. There is also a "Law of Demeter for Adaptive Programs" (abbreviated LoD-AP) which is a bit stronger than the LoD described above (which Lieberherr calls the Law of Demeter for Functions (or Methods). The Demeter/Adaptive Programming home page is at http://www.ccs.neu.edu/research/demeter/ Dr. Lieberherr also published a book on the Demeter method last September: Adaptive Object-Oriented Software: The Demeter Method with Propagation Patterns by Dr. Karl J. Lieberherr PWS Publishing Company, 1996 ISBN: 0-534-94602-X I was fortunate enough to take a graduate class from Dr. Lieberherr on the Demeter method and Adaptive O-O Programming. -- Brad_Appleton@email.mot.com Motorola AIEG, Northbrook, IL USA "And miles to go before I sleep." DISCLAIMER: I said it, not my employer!