

% 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{Did You Really Understand Super?}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W6S01}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What You Will Learn}

Revisit 

\begin{itemize}
\item \code{super}
\item Message lookup
\item Class methods
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{A Little Puzzle}

\begin{listing}{}
Dice class >> new

  | inst |
  inst := super new. 
  inst initialize.
  ^ inst
\end{listing}

We execute the following expression: \code{Dice new} 
\end{frame}



\begin{frame}[fragile]

\frametitle{Questions}

\begin{listing}{}
Dice class >> new

  | inst |
  inst := super new. 
  inst initialize.
  ^ inst
\end{listing}

\begin{itemize}
\item What is \code{inst}?
\item What is \code{super}?
\item What is \code{super new}?
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Hint: super is Not...}

\begin{listing}{}
Dice class >> new

  | inst |
  inst := super new. 
  inst initialize.
  ^ inst
\end{listing}

\begin{itemize}
\item No \code{super} is not the superclass
\item No \code{inst} is not an instance of the superclass
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Hint 2: super is the Message Receiver}

\begin{listing}{}
Dice class >> new

  | inst |
  inst := super new. 
  inst initialize.
  ^ inst
\end{listing}

\begin{itemize}
\item The message is \code{Dice new}
\item So the receiver is the class \code{Dice}
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Sending a Message: Lookup + Apply on Receiver}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Remember: Method Lookup}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Solution}
% syntax highlighting = smalltalk

\begin{listing}{}
Dice class >> new

  | inst |
  inst := super new. 
  inst initialize.
  ^ inst
\end{listing}

\begin{itemize}
\item \code{super} is the receiver: the class \code{Dice}
\item Look for \code{new} in the superclass of the class \code{Dice class} (Pay attention not \code{Dice})
\item Once found we apply to the receiver: \code{Dice}
\item We get an instance of the class \code{Dice} and send it initialize and return it
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Solution}


\begin{center}
\includegraphics[width=1.3\textwidth]{figures/Workstation-Dice-MetaclassesWithInheritanceWithLookup.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Summary}

\begin{itemize}
\item Sending a message is looking up for the method and applying it on the receiver
\item Now you should really understand \code{super} :)
\item \code{super} is the receiver of the message and the method lookup starts in the superclass of the class  containing the expression
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Challenge?}
\end{frame}



\begin{frame}[fragile]

\frametitle{Challenge!}

Imagine we have 

\begin{listing}{}
A >> foo
   ^ super class == self class 
\end{listing}

What is the result of \code{A new foo} and why?
\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:
