

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

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{What You Will Learn}

\begin{itemize}
\item Not needed to program in Pharo :)
\item But intellectually exciting
\begin{itemize}
\item Where \code{new} is defined?
\item What is the class of a metaclass?
\item Uniformity of the instance relationship
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{The Key: Only One Method Lookup}

\begin{columns}

\begin{column}{0.6\textwidth}

When a message is sent to an object, a method is searched starting from the class of the object and following the inheritance chain
\end{column}


\begin{column}{0.4\textwidth}


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

\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item Every object is an instance of a class
\item Every class eventually inherits from \code{Object}
\item Every class is an instance of a metaclass
\item The metaclass hierarchy parallels the class hierarchy
\item Every metaclass inherits from \code{Class} up to \code{Behavior}
\item Every metaclass is an instance of \code{Metaclass}
\item The metaclass of \code{Metaclass} is an instance of \code{Metaclass}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item \textbf{Every object is an instance of a class}
\item Every class eventually inherits from \code{Object}
\item Every class is an instance of a metaclass
\item The metaclass hierarchy parallels the class hierarchy
\item Every metaclass inherits from \code{Class} up to \code{Behavior}
\item Every metaclass is an instance of \code{Metaclass}
\item The metaclass of \code{Metaclass} is an instance of \code{Metaclass}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Every Object is an Instance of a Class}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item Every object is an instance of a class
\item \textbf{Every class eventually inherits from \code{Object}}
\item Every class is an instance of a metaclass
\item The metaclass hierarchy parallels the class hierarchy
\item Every metaclass inherits from \code{Class} up to \code{Behavior}
\item Every metaclass is an instance of \code{Metaclass}
\item The metaclass of \code{Metaclass} is an instance of \code{Metaclass}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Every Class Eventually Inherits From Object}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Responsibility of Object}

Class \code{Object} represents the common object behavior

\begin{itemize}
\item error handling, halting, announcements
\item all classes eventually inherit from \code{Object} 
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item Every object is an instance of a class
\item Every class eventually inherits from \code{Object}
\item \textbf{Every class is an instance of a metaclass}
\item The metaclass hierarchy parallels the class hierarchy
\item Every metaclass inherits from \code{Class} up to \code{Behavior}
\item Every metaclass is an instance of \code{Metaclass}
\item The metaclass of \code{Metaclass} is an instance of \code{Metaclass}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Every class is an instance of a metaclass}

Classes are objects too!

\begin{itemize}
\item Every class \code{X} is the unique instance of its metaclass, called \code{X class}
\end{itemize}


\begin{center}
\includegraphics[width=1.1\textwidth]{figures/04-OrderedCollectionIsInstanceOfOrderedCollectionClass.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclass are Implicit}

Metaclasses are automatically created when creating a class
\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item Every object is an instance of a class
\item Every class eventually inherits from \code{Object}
\item Every class is an instance of a metaclass
\item \textbf{The metaclass hierarchy parallels the class hierarchy}
\item Every metaclass inherits from \code{Class} up to \code{Behavior}
\item Every metaclass is an instance of \code{Metaclass}
\item The metaclass of \code{Metaclass} is an instance of \code{Metaclass}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclass Hierarchy Parallels Class Hierarchy}


\begin{center}
\includegraphics[width=1.2\textwidth]{figures/05-OrderedCollectionIsInstanceOfOrderedCollectionClassInherit}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Sending a Message to a Class}


\begin{center}
\includegraphics[width=1.4\textwidth]{figures/06-OrderedCollectionIsInstanceOfOrderedCollectionClass}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Questions}

\begin{itemize}
\item What is the class of a metaclass?
\item What is the superclass of \code{Object class}?
\item What about sending a message to a metaclass?
\end{itemize}


\begin{center}
\includegraphics[width=1.1\textwidth]{figures/07-2Questions.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item Every object is an instance of a class
\item Every class eventually inherits from \code{Object}
\item Every class is an instance of a metaclass
\item The metaclass hierarchy parallels the class hierarchy
\item \textbf{Every metaclass inherits from \code{Class} up to \code{Behavior}}
\item Every metaclass is an instance of \code{Metaclass}
\item The metaclass of \code{Metaclass} is an instance of \code{Metaclass}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Every Metaclass Inherits from Class up to Behavior}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Where new is Defined?}


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Responsibilities of Behavior}

\code{Behavior}

\begin{itemize}
\item Minimum state for objects that \textbf{have instances}
\item State:
\begin{itemize}
\item superclass link, method dictionary, description of instances (representation and number)
\end{itemize}

\item Methods:
\begin{itemize}
\item method dictionary, compiling method
\item instance creation (\code{new}, \code{basicNew}, \code{new:}, \code{basicNew:})
\item class hierarchy manipulation (\code{superclass:}, \code{addSubclass:}) 
\item accessing (\code{selectors}, \code{allSelectors}, \code{compiledMethodAt:}, \code{allInstances}, \code{instVarNames}) 
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Responsibilities of ClassDescription}

\code{ClassDescription}

\begin{itemize}
\item Abstract class superclass of \code{Class} and \code{Metaclass}
\item Adds a number of facilities to \code{Behavior}:
\begin{itemize}
\item named instance variables
\item category organization for methods
\item the notion of a name (abstract)
\item maintenance of Change sets and logging changes
\item most of the mechanisms needed for fileOut
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Responsibilities of Class}

\code{Class}

\begin{itemize}
\item represents the common behavior of all classes
\begin{itemize}
\item name, compilation, method storing, instance variables ...
\end{itemize}

\item representation for classVariable names (\code{addClassVarName:}, \code{initialize})
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Classes are Instances of Metaclasses}

Metaclass and class inheritances are parallel


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

\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item Every object is an instance of a class
\item Every class eventually inherits from \code{Object}
\item Every class is an instance of a metaclass
\item The metaclass hierarchy parallels the class hierarchy
\item Every metaclass inherits from \code{Class} up to \code{Behavior}
\item \textbf{Every metaclass is an instance of \code{Metaclass}}
\item The metaclass of \code{Metaclass} is an instance of \code{Metaclass}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Every Metaclass is an Instance of Metaclass}

\code{Metaclass} inherits from \code{ClassDescription}

\begin{center}
\includegraphics[width=1.15\textwidth]{figures/11-BehaviorClassDescriptionAndClassWithMetaclassesInstanceOfMetaclass.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclass Responsibilities}

\code{Metaclass} is responsible for creating and initializing a metaclass's sole instance (a Class)
\end{frame}



\begin{frame}[fragile]

\frametitle{Metaclasses in 7 Points}

\begin{enumerate}
\item Every object is an instance of a class
\item Every class eventually inherits from \code{Object}
\item Every class is an instance of a metaclass
\item The metaclass hierarchy parallels the class hierarchy
\item Every metaclass inherits from \code{Class} up to \code{Behavior}
\item Every metaclass is an instance of \code{Metaclass}
\item \textbf{The metaclass of \code{Metaclass} is an instance of \code{Metaclass}}
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{The metaclass of Metaclass is an Instance of Metaclass}


\begin{center}
\includegraphics[width=1.3\textwidth]{figures/12-FullMetaclasses.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Observations}

\begin{columns}

\begin{column}{0.7\textwidth}

\begin{itemize}
\item When programming we do not really care about that!
\item Now the full graph is consistent
\begin{itemize}
\item Any class can receive a message 
\item Only one message lookup
\end{itemize}

\end{itemize}
\end{column}


\begin{column}{0.3\textwidth}


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

\end{column}

\end{columns}

\end{frame}



\begin{frame}[fragile]

\frametitle{A Consistent World}


\begin{center}
\includegraphics[width=1.3\textwidth]{figures/12-FullMetaclasses.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{What You Should Know}

\begin{itemize}
\item Classes are objects and can receive messages
\item The process is \textbf{exactly} the same as for any other objects
\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:
