

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

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Class and Method Definitions in Pharo}

\begin{itemize}
\item classes and methods are defined within tools
\item there is no dedicated syntax
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Class Definition in Pharo}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Class Definition is a Message}

\begin{listing}{}
Object subclass: #Point
  instanceVariableNames: 'x y'
  classVariableNames: ''
  package: 'Graphics'
\end{listing}

We send the message \code{subclass:inst....} to the superclass to create the class
\end{frame}



\begin{frame}[fragile]

\frametitle{Method Definition in Pharo}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Method Definition in Pharo}

\begin{listing}{}
factorial
  "Answer the factorial of the receiver."
  self = 0 ifTrue: [ ^ 1 ].
  self > 0 ifTrue: [ ^ self * (self - 1) factorial ].
  self error: 'Not valid for negative integers'
\end{listing}

In which class is \code{factorial} defined?
\end{frame}



\begin{frame}[fragile]

\frametitle{Presentation Convention}

In this lecture, a method will be displayed as

\begin{listing}{}
Integer >> factorial
  "Answer the factorial of the receiver."
  self = 0 ifTrue: [ ^ 1 ].
  self > 0 ifTrue: [ ^ self * (self - 1) factorial ].
  self error: 'Not valid for negative integers'
\end{listing}

\begin{itemize}
\item \textbf{Integer \textgreater{}\textgreater{}} is not part of the syntax
\begin{itemize}
\item it tells you the method's class
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Presentation Convention}


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


In Pharo, the method belongs to the selected class
\end{frame}



\begin{frame}[fragile]

\frametitle{Remember Messages}

\begin{listing}{}
Integer >> factorial
  "Answer the factorial of the receiver."

  self = 0 ifTrue: [ ^ 1 ].
  self > 0 ifTrue: [ ^ self * (self - 1) factorial ].
  self error: 'Not valid for negative integers'
\end{listing}

\begin{itemize}
\item \code{factorial} is the method name
\item \code{=}, \code{\textgreater{}}, \code{*} and \code{-} are binary messages
\item \code{factorial} is an unary message
\item \code{ifTrue:} and \code{error:} are keyword messages
\item the caret \code{\string^} is for returning a value
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{A Method Returns self by Default}

\begin{listing}{}
Game >> initializePlayers
  self players
    at: 'tileAction'
    put: ( MITileAction director: self )
\end{listing}

is equivalent to

\begin{listing}{}
Game >> initializePlayers
  self players
    at: 'tileAction'
    put: ( MITileAction director: self ).
  ^ self       "<-- optional"
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Class Methods}

\begin{columns}

\begin{column}{0.6\textwidth}


\begin{center}
\includegraphics[width=0.9\textwidth]{figures/Point-xy-class-method.png}\end{center}

\end{column}


\begin{column}{0.4\textwidth}

\begin{itemize}
\item press the button \code{class} to define a class method
\item in lectures, we add \code{class}
\end{itemize}
\end{column}

\end{columns}


\begin{listing}{}
Point class >> x: xInteger y: yInteger 
  "Answer an instance of me with coordinates xInteger and yInteger."

  ^ self basicNew setX: xInteger setY: yInteger
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{What You Should Know}

\begin{itemize}
\item A class is defined by sending a message to its superclass 
\item Classes are defined inside packages
\item Methods are public
\item By default a method returns the receiver, \code{self}
\item Class methods are just methods of the class side
\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:
