

% 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{DoesNotUnderstand: a Precious Hook}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W7S05}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{When No Method is Found}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{doesNotUnderstand: is a Message}

\begin{itemize}
\item \code{doesNotUnderstand:} is a message
\item Every class can customize this hook
\item Important hook for automatic delegation, distributed programming and many other usages
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example 1: Delegation}

Redirect unknown messages to another object (a target)
\end{frame}



\begin{frame}[fragile]

\frametitle{Example 1: Delegation}

\begin{listing}{}
Object subclass: #Delegating
   instanceVariableNames: 'target'
\end{listing}

\begin{listing}{}
Delegating >> doesNotUnderstand: aMessage
   ^ aMessage sendTo: self target
\end{listing}

\begin{itemize}
\item Pay attention it blurs code understandability
\item Only tools and specific parts should use such tricks
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example 2: A LoggingProxy}

Basic idea:

\begin{itemize}
\item Create a 'minimal' object raising error to most messages
\item Customize its \code{doesNotUnderstand:} method
\item Swap an object and the proxy
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Implementing LoggingProxy}

\begin{listing}{}
ProtoObject subclass: #LoggingProxy
	instanceVariableNames: 'subject invocationCount'
	classVariableNames: ''
	package: 'LoggingProxy'
\end{listing}

\begin{listing}{}
LoggingProxy >> initialize 
	invocationCount := 0. 
	subject := self
	"will be swapped by become:"
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Customize doesNotUnderstand:}

\begin{listing}{}
LoggingProxy >> doesNotUnderstand: aMessage
	Transcript show: 'performing ', aMessage printString; cr.
	invocationCount := invocationCount + 1.
	^ aMessage sendTo: subject
\end{listing}

\begin{listing}{}
Message >> sendTo: receiver
   ^ receiver perform: selector withArguments: args
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Message Behavior}

\begin{listing}{}
| point |
point := 1@2.
LoggingProxy new become: point.
self assert: point invocationCount = 0.
self assert: point x + point y = 3.
self assert: point + (3@4) = (4@6).
self assert: point invocationCount = 3.
\end{listing}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Some Limits of such Minimal Objects}

\begin{itemize}
\item Messages sent by the object to itself are not trapped!
\item Class cannot be swapped
\item What to do with messages that are understood by both the minimalObject and its subject?
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Another Application}

Scaffolding patterns: Generate code on the fly based of patterns

\begin{listing}{}
DynamicAccessors >> doesNotUnderstand: aMessage
   | messageName |
   messageName := aMessage selector asString.
   (self class instVarNames includes: messageName)
      ifTrue: [self class compile:
                  messageName , String cr , ' ^ ' , messageName.
         ^ aMessage sendTo: self].
   super doesNotUnderstand: aMessage
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Conclusion}

Minimal Objects

\begin{itemize}
\item Basis for proxies
\item Multiple usages (distribution, object loading, spying)
\end{itemize}

\code{doesNotUnderstand:}

\begin{itemize}
\item Powerful hook
\item Only to be used when needed
\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:
