Assuring Good Style for Object-Oriented Programs

The Law of Demeter states that each method can send messages to only a limited set of objects: to argument objects, to itself, to objects either created in the method or in global variables, and to the immediate subpart of self (elements or object instantiated within the class). These are the preferred-supplier objects of the method.

Note: The self construct in Smalltalk and Flavors is called “this” in #cpp and “Current” in Eiffel.

It is to organise and reduce dependencies (a class calls a function defined in other class) between classes. Such practice promote maintainability and comprehensibility of the codebase.

Links to this page
  • The Pragmatic Programmer

    Follow the Law of Demeter @Lieberherr1989#, i.e. any method of an object should call only methods belonging to itself (self or functions defined in the class), parameters passed into the method and objects created within the method or its class. (See more in https://www.ccs.neu.edu/research/demeter)

  • Law of Demeter

    The Law of Demeter introduced by Assuring Good Style for Object-Oriented Programs# states that each method or function can send messages to their preferred-supplier objects, that is, argument objects, itself, objects either created in the method or in global scope, and the immediate subpart of self such as elements or object instantiated within the class. This also means that they should call only methods belonging to itself, parameters passed into the method (class type object), objects created within the method or its class. The Pragmatic Programmer

#oop #literature #cpp