

% 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{Class Methods At Work}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W4S06}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What You Will Learn}

\begin{itemize}
\item Class methods are normal methods
\item Most class methods create new instances
\begin{itemize}
\item but they can be used for other things
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Parsing Lines}

Imagine we want to parse

\begin{listing}{}
!Section Title
- list item
-- subitem

Any text here
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{A Possible Design}


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


\begin{itemize}
\item Document item \textbf{classes} know
\begin{itemize}
\item if they can parse a line (\code{canParse:})
\item how to create instances (\code{newFromLine:})
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Parsing Lines}


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


\begin{listing}{}
Parser >> documentClasses
   ^ DocumentItem allSubclasses
      sorted: [ :class1 :class2 | class1 priority < class2 priority ]

Parser >> parse: line
   self documentClasses
      detect: [ :subclass |
         (subclass canParse: aLine)
            ifTrue: [ ^ subclass newFromLine: line ] ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{The Command-Line Handler}

\begin{itemize}
\item the Pharo command-line interface (CLI) uses the same approach
\item each subclass of \code{CommandLineHandler} knows how to deal with one command
\item the correct subclass is selected by sending messages to the class
\end{itemize}
% syntax highlighting = bash

\begin{listing}{}
$ pharo Pharo.image eval "10 factorial"
3628800
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{The Command-Line Handler}

\begin{listing}{}
CommandLineHandler class >> isResponsibleFor: arguments
   ^ arguments includesSubCommand: self commandName

EvaluateCommandLineHandler class >> commandName
   ^ 'eval'

CommandLineHandler class >> allHandlers
   ^ self allSubclasses
      reject: [ :handler| handler isAbstract ]

CommandLineHandler class >> handlersFor: arguments
   ^ self allHandlers
      select: [ :handlerClass |
         handlerClass isResponsibleFor: arguments ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Conclusion}

\begin{itemize}
\item Classes are objects and can be sent messages
\item Method lookup is exactly the same as for all objects:
\begin{itemize}
\item go to the class of the receiver 
\item follow inheritance chain
\end{itemize}

\item More during the lecture \textit{Understanding Metaclasses}
\item Pharo makes it easy to iterate over subclasses
\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:
