

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Inheritance and Lookup}
\subtitle{2: Lookup}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W4S02}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Goal}

\begin{itemize}
\item Understanding
\begin{itemize}
\item message sending
\item method lookup
\item semantics of \code{self}
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Inheritance}

\begin{itemize}
\item Inheritance of state is static
\item Inheritance of behavior is dynamic
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Message Sending}

\begin{columns}

\begin{column}{0.38\textwidth}

\textbf{Sending} a \textbf{message} is a two-step process:

\begin{enumerate}
\item \textbf{look up} the \textbf{method} matching the message
\item execute this method on the \textbf{receiver}
\end{enumerate}
\end{column}


\begin{column}{0.62\textwidth}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/InheritanceDiagram-sendingMessage.png}\end{center}

\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{Method Lookup}

\begin{columns}

\begin{column}{0.38\textwidth}

The lookup starts in the \textbf{class} of the \textbf{receiver} then:

\begin{itemize}
\item if the method is defined in the class, it is returned
\item otherwise the search continues in the superclass
\end{itemize}
\end{column}


\begin{column}{0.62\textwidth}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/InheritanceDiagram-lookupTwoStages.png}\end{center}

\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{Some Lookup Cases}

\begin{columns}

\begin{column}{0.47\textwidth}

Sending the message \code{color} to \code{aColoredRectangle}
\end{column}


\begin{column}{0.53\textwidth}


\begin{center}
\includegraphics[width=0.95\textwidth]{figures/InheritanceDiagram-lookup-superclass.png}\end{center}

\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{Some Lookup Cases}

\begin{columns}

\begin{column}{0.47\textwidth}

Sending the message \code{area} to \code{aColoredRectangle}
\end{column}


\begin{column}{0.53\textwidth}


\begin{center}
\includegraphics[width=0.95\textwidth]{figures/InheritanceDiagram-lookup-superclass.png}\end{center}

\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{self Always Represents the Receiver}


\begin{center}
\includegraphics[width=0.71\textwidth]{figures/LookupWithSelfInSuperclassMethod.png}\end{center}


\begin{listing}{}
A new foo
> ...
B new foo
> ...
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{self Always Represents the Receiver}


\begin{center}
\includegraphics[width=0.71\textwidth]{figures/LookupWithSelfInSuperclassMethod.png}\end{center}


\begin{listing}{}
A new foo
> 10
B new foo
> 50
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{What is self/this?}

Take 5 min and write the definition of \code{self} (\code{this} in Java).

\begin{itemize}
\item your definition should have two points:
\begin{itemize}
\item what does \code{self} represent?
\item how is a method looked up when a message is sent to \code{self}?
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{self/this}

\begin{itemize}
\item \code{self} represents the receiver of the message
\item \code{self} in Pharo, \code{this} in Java
\item The method lookup starts in the class of the receiver
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{self Always Represents the Receiver}


\begin{center}
\includegraphics[width=0.71\textwidth]{figures/LookupWithSelfInSuperclassMethod.png}\end{center}


\begin{listing}{}
A new bar
> ...
B new bar
> ...
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{self Always Represents the Receiver}


\begin{center}
\includegraphics[width=0.71\textwidth]{figures/LookupWithSelfInSuperclassMethod.png}\end{center}


\begin{listing}{}
A new bar
> 10
B new bar
> 50
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{self Always Represents the Receiver}

\begin{columns}

\begin{column}{0.35\textwidth}


\begin{center}
\includegraphics[width=1.1\textwidth]{figures/LookupWithSelfInSuperclassMethod.png}\end{center}


\begin{listing}{}
    B new bar
    > 50
\end{listing}
\end{column}


\begin{column}{0.65\textwidth}

Evaluation of \code{aB bar}

\begin{enumerate}
\item \code{aB}'s class is \code{B}
\item no method \code{bar} in \code{B}
\item look up in \code{A} - \code{bar} is found
\item method \code{bar} is executed
\item \code{self} refers to the receiver \code{aB}
\item \code{foo} is sent to \code{self}
\item look up \code{foo} in the \code{aB}'s class: \code{B}
\item \code{foo} is found there and executed
\end{enumerate}
\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{self Always Represents the Receiver}

\begin{columns}

\begin{column}{0.6\textwidth}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/LookupWithSelfInSuperclassMethodThreeClasses.png}\end{center}

\end{column}


\begin{column}{0.4\textwidth}

\begin{listing}{}
    A new bar
    > ...
    B new bar
    > ...
    C new bar
    > ...
\end{listing}
\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{self Always Represents the Receiver}

\begin{columns}

\begin{column}{0.6\textwidth}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/LookupWithSelfInSuperclassMethodThreeClasses.png}\end{center}

\end{column}


\begin{column}{0.4\textwidth}

\begin{listing}{}
    A new bar
    > 10
    B new bar
    > 10
    C new bar
    > 50
\end{listing}
\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{What You Should Know}

\begin{itemize}
\item \code{self} always represents the receiver
\item Sending a message is a two-step process:
\begin{enumerate}
\item Look up the method matching the message
\item Execute this method on the receiver
\end{enumerate}

\item Method lookup maps a message to a method
\item Method lookup starts in the class of the receiver
\begin{itemize}
\item ...and goes up in the hierarchy
\end{itemize}

\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
