\section{Overloading and dynamic method selection}

The Law of Demeter attempts to limit certain dependencies on types
of objects occurring within methods.  In an
\oo\ program there may be many methods defined having the same name.
Determining which of these is to be executed when the name is evoked
depends on the types of one or more of the arguments.  
The language C++ allows overloading using the argument types.
At first glance, this looks like the same kind of multi-argument method 
selection described above.  However, this is not the case.  In C++ only
the object whose member function is called
is used for dynamic method selection and member functions 
are only ``attached'' to the class they are defined for.
Therefore only data member classes
of the attached class are potential preferred suppliers and not 
data member classes
of the classes of the arguments of the member function.  
Overloading is a syntactic device
dealt with at compile-time, distinct from the semantic device of dynamic
method selection which is done at run-time.

For C++ the message passing formulation of the Law is appropriate.
We view the compile-time method selection of C++ due to overloading
as syntactic sugar. We could always rename the methods by prefixing
their names with argument types to avoid the need of overloading.
But CLOS is inherently more powerful: it does true dynamic method
selection 
on all the method selection arguments.
%Therefore we need for CLOS the generalization of the Law as proposed
%in the section on ``Formulation for existing languages''..


\section{The Law in mixed paradigm languages}

In languages which support both the action-oriented and the object-oriented
paradigm we have the coexistence of function or procedure calls with
message sendings or generic function calls. We can view a regular
function or procedure as a degenerate generic function with zero method
selection arguments. Therefore the Law of Demeter does not restrict
the regular function or procedure calls inside a method.


However, we do want to restrict the use of generic functions with
one or more method selection arguments within regular functions.
Outside methods we tend to disallow generic function calls, i.e., a regular
function or procedure should not contain generic function calls.  
In languages such as C++, the main program is an exception: it is allowed to
contain calls of member functions.

%This means
%that when a shift of paradigm from \oo\ to action oriented is neccessary
%it should be consistent.

For mixed paradigm languages it makes sense to distinguish between 
types and classes. The types include:
\begin{itemize}
\item
the types of the action-oriented base language
such as character, integer, real and other types,
\item the classes of the object-oriented extension.
\end{itemize}

In CLOS many but not all Common Lisp types are classes and all
classes are types.


