\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
LAW OF DEMETER (Smalltalk-80, object version) 

In all message expressions inside a method M 
the receiver must be one of the following objects:
\begin{enumerate}
\item
an argument object of M including objects in 
      pseudo variables "self" and "super" or
\item
an instance variable object of the class to which M
      is attached or
\item
an object created by M or by methods which it calls or
\item
  an object in a global variable.
  \end{enumerate}

%\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: We assume that the user can determine 
for each generic function the number of method selection
arguments (not necessarily all required ones) and that this number is
part of the interface of the generic function.
A method selection argument is an argument which is used
for identifying the applicable methods.

\noindent
LAW OF DEMETER (CLOS, object version) 

All function calls inside a method M must use only the 
following objects as method selection arguments:
\begin{enumerate}
\item
M's argument objects or
\item
slot values of method selection argument classes of M or
\item
objects created by method M, or by functions which
    M calls or
\item
objects in global variables.
\end{enumerate}

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
LAW OF DEMETER (Old Flavors, object version) 

In any method M attached to class C send only messages 
to the following objects:
\begin{enumerate}
\item
M's argument objects or
\item
the instance variable objects of C or
\item
objects created by method M, or by methods or 
      functions which M calls or
\item
objects in global variables.
\end{enumerate}

%\noindent
%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
%\begin{enumerate}
%\item
%argument classes of M or
%\item
%instance variable classes of C or
%\item
%classes of objects created by method M, 
%      or by methods or functions which M calls or
%\item
%classes of objects in global variables.
%\end{enumerate}


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

\item
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:
\begin{enumerate}
\item
  an argument object of M or
\item
  an attribute object of the class in which M is defined or
\item
  an object created by M
      or by routines which M calls.
\end{enumerate}

\end{itemize}

