\section{Compile Time Checking of the Law}

The Law of Demeter (the original version, not the object version)
can be checked at compile-time for useful subsets of object-oriented
languages. Checking the Law is closely related to static type checking
since we need all the type information to check the Law.
When a language supports static type checking, we can enforce the Law.
It is not necessary that the user gives a type to all the
variables.
This checking requires that the class dictionary for the
application be available at compile time since it contains all the necessary
type information.  The compile time checking is facilitated when
all the arguments and
return values of methods are typed by the user.  

In not strongly typed languages there are several cases
which cannot be checked at compile time.  

\begin{itemize}

\item
Class and/or Method Definitions at Run Time

This occurs in some interpreted languages such as Lisp/Flavors and CLOS.
Since these are defined at run time it is impossible to check them for 
consistency with the Law of Demeter at compile time.

\item
Passing a Message as an Argument

The following example demonstrates the passing of a method as an argument to
another method.  In the receiver method, the passed message is sent to an 
object ``o''.

\begin{verbatim}
(defmethod (X :xyz) (m)
  (send (send o m) ':m2)))
\end{verbatim}

If we don't know the argument types  and the result type of 
m we cannot check the Law at compile time.

\item
Dynamic Message Name Calculation

The following example demonstrates a case which cannot be tested at compile
time.

\begin{verbatim}
(send (send o (concat ': some-string)) ':m)
\end{verbatim}

The string named ``some-string'' could be read in at run time in which case
there is no way of knowing the signature of the message sent to ``o''.  
\end{itemize}





