\section{Formulations for existing languages}

We give the formulation of some of the Law of Demeter 
versions in a few object-oriented languages.
Each formulation adapts the Law to the terminology of the particular language.
\begin{itemize}
\item
Smalltalk-80:
object/ type,
message passing.

\bv
----- LAW OF DEMETER (Smalltalk-80, object version) ----
In all message expressions inside a method M 
the receiver must be one of the following objects:
  - an argument object of M including objects in 
      pseudo variables "self" and "super" or
  - an instance variable object of the class to which M
      is attached.
(Objects created by the method, or by methods which it calls,
and objects in global 
variables are viewed as being passed by arguments.)
--------------------------------------------------------
\end{verbatim}

\item
C++:
type, 
message passing.

C++ allows overloading of function names
with respect to several arguments.
But run-time implicit case analysis is done only with the first argument.
\bv
----- LAW OF DEMETER (C++, type version) -------------
Every member or friend function M of a 
class C is only allowed to call member
or friend functions of the following classes:
  - The argument classes of M (including C),
  - The data member classes of C,
  - The classes of objects created by M (directly, 
      by calling a constructor function or indirectly, 
      by calling a function which will call 
      eventually a constructor function)
  - The classes of global objects.
----------------------------------------------------------
\end{verbatim}

\item
CLOS:
object/ type,
generic function.

\bv
----- LAW OF DEMETER (CLOS, object version) -------------
All function calls inside a method M must use only the 
following objects as method selection arguments:
- M's argument objects or
- slot values of method selection argument classes of M.
(Objects created by the method, or by functions which
it calls, and objects in global variables are viewed as 
being passed by arguments.
A method selection argument is an argument which is used
for identifying the applicable methods.)
----------------------------------------------------------
\end{verbatim}
Note that this formulation implies that the only legal use of
function slot-value is on method selection arguments.

\bv
----- LAW OF DEMETER (CLOS, pure type version) -----------
In all function calls inside a method M all method 
selection argument objects must belong to one of the 
following classes:
  - argument classes of M
  - slot classes of method selection argument classes of M.
----------------------------------------------------------
\end{verbatim}
\item
Old Flavors:
object/ type,
message passing.
\bv
----- LAW OF DEMETER (Old Flavors, object version) -----
In any method M attached to class C send only messages 
to the following objects:
  - M's argument objects
  - the instance variable objects of C.
(Objects created by the method, or by methods or functions
which it calls, and objects in global 
variables are considered as arguments of M.)
--------------------------------------------------------
\end{verbatim}
\bv
----- LAW OF DEMETER (Old Flavors, associated classes) ---
In any method M attached to class C send only messages
to instances of classes associated with the following classes
  - argument classes of M
  - instance variable classes of C.
(Objects created by the method, or by methods or functions
which it calls, and objects in global
variables are considered as arguments of M.)
----------------------------------------------------------
\end{verbatim}


\item
New Flavors:
object/ type,
generic function.

\item
Eiffel:
object/ type,
generic function.

\bv
----- LAW OF DEMETER (Eiffel, object version) -----------
In all calls of routines inside a routine M 
the entity object must be one of the following objects:
  - an argument object of M
  - an attribute object of the class in which M is defined.
---------------------------------------------------------
\end{verbatim}
\end{itemize}

These formulations can be altered in the following ways:
\begin{itemize}
\item Use nested universal quantifiers. For all classes C, and for all methods M attached to C, ...

\item Use ``let'' phrases. Let C be any class, let M be any method attached to C,
let E be any message expression ...
\end{itemize}

