

% 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{3: super}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W4S03}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Goal}

\begin{itemize}
\item Sending a message
\item Method lookup
\item \code{super} semantics and the differences with \code{self}
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{What is super?}

Take 5 min and write the definition of \code{super}

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

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Challenge Yourself With super!}

\begin{columns}

\begin{column}{0.8\textwidth}


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

\end{column}


\begin{column}{0.3\textwidth}

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

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{Challenge Yourself With super!}

\begin{columns}

\begin{column}{0.8\textwidth}


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

\end{column}


\begin{column}{0.3\textwidth}

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

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{super Changes Where the Lookup Starts}

\begin{columns}

\begin{column}{0.54\textwidth}


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

\end{column}


\begin{column}{0.46\textwidth}

Evaluation of \code{aC bar}

\begin{enumerate}
\item \code{aC}'s class is \code{C}
\item no method \code{bar} in C
\item look up in \code{B} - \code{bar} is found
\item method \code{bar} is executed
\item \code{bar} is sent to \code{super}
\item \code{super} is \code{aC} but lookup starts in \code{A}
\item \code{bar} is found in \code{A} and executed
\item \code{foo} is sent to \code{aC}
\item \code{foo} is found in \code{C}
\end{enumerate}
\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{super Changes Where the Lookup Starts}

\begin{itemize}
\item \code{super} refers to the receiver of the message (just like \code{self})
\item The method lookup starts in the superclass of \textbf{the class containing the \code{super} expression}
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{self is Dynamic}

\begin{columns}

\begin{column}{0.45\textwidth}


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

\end{column}


\begin{column}{0.55\textwidth}

We don't know which \code{foo} method \code{bar} refers to
\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{super is Static}

\begin{columns}

\begin{column}{0.5\textwidth}


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

\end{column}


\begin{column}{0.5\textwidth}

\begin{itemize}
\item at compilation-time, we know that \code{B\textgreater{}\textgreater{}foo} refers to \code{A\textgreater{}\textgreater{}foo}
\item we should look above the class containing the \textbf{method} using \code{super}
\end{itemize}
\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{Even Some Books Got it Wrong}

\begin{itemize}
\item \textbf{Wrong} definition: \textit{\code{super} looks for the method in the superclass of the \textbf{receiver}'s class}
\item With this definition, this example would loop forever:
\end{itemize}


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


In reality it \textbf{does not} loop, the definition is wrong
\end{frame}



\begin{frame}[fragile]

\frametitle{What You Should Know}

\begin{itemize}
\item \code{self} always represents the receiver
\item \code{super} always represents the receiver
\item \code{super} changes the lookup:
\begin{itemize}
\item a super send starts the lookup in the class above it
\end{itemize}

\item self sends act as a hook: code of subclasses may be invoked
\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:
