diff --git a/oop/oop.pdf b/oop/oop.pdf index 817319fdc85fc59211bc3803cd0f86fd516254d0..bf3d10559c5767a897914f56684385f566fb94c7 100644 Binary files a/oop/oop.pdf and b/oop/oop.pdf differ diff --git a/oop/oop.tex b/oop/oop.tex index ad08e1eccfe2ecef305f9e11f64bdb4cb2c0b209..9dd075f9216ef476965ffc77a127f8abcd103fa3 100644 --- a/oop/oop.tex +++ b/oop/oop.tex @@ -45,7 +45,7 @@ \begin{minted}{python} vectors_x = [0, 1, 2] vectors_y = [0, 1, 1] ->>> (vectors_x[2], vectors_y[1]) +>>> (vectors_x[2], vectors_y[2]) (2, 1) \end{minted} @@ -89,7 +89,7 @@ interaction. \item \mintinline{python}{42} is an instance of type \mintinline{python}{int}; \item \mintinline{python}{'Hello World!'} is an instance of type -\mintinline{python}{string}. +\mintinline{python}{str}. \end{itemize} \end{itemize} \end{frame} @@ -161,15 +161,21 @@ Data and procedures (functions) that ``belong'' to the class: \begin{itemize} \item \textcolor{pms280_compl}{Data} attributes: the objects that make up -the class; +the class: +\begin{itemize} \item a 2d vector is made up of two numbers (\mintinline{python}{x} and \mintinline{python}{y}). -\item \textcolor{pms280_compl}{Methods} (procedures); +\end{itemize} + +\item \textcolor{pms280_compl}{Methods} (procedures): +\begin{itemize} \item functions that \emph{only} work with this class; \item how to interact with the object; \item e.g., calculate the length of a vector. \end{itemize} +\end{itemize} + \bigskip \mintinline{python}{self} is the current instance of a class. @@ -198,7 +204,7 @@ instance; \end{itemize} \end{frame} -\begin{frame}[fragile]{Hiding information --- separation of concern} +\begin{frame}[fragile]{Hiding information --- separation of concerns} \begin{itemize} \item Sometimes we would like to \textcolor{pms280_compl}{hide} attributes to the outside world, i.e., only usable inside the class. @@ -210,13 +216,13 @@ class Vector(object): def __init__(self, x=0, y=0): self.x = x self.y = y - self._secret = 42 + self._secret = 42 # this is allowed \end{minted} \item we agree not to access this attribute directly: \begin{minted}{python} >>> v1 = Vector(1, 2) ->>> print v1._secret # this is forbidden +>>> print v1._secret # this is forbidden \end{minted} \end{itemize} @@ -290,8 +296,11 @@ class Vector(object): \begin{minted}{python} >>> v1 = Vector(4, 3) >>> print type(v1) -<class '__main__.Vector'> \end{minted} +%% start minted fix +\vspace{-.08cm} +\mintinline{python}{<class}\mintinline{python}{ '__main__.Vector'>} +%% end minted fix \item that also works for the class: \begin{minted}{python} @@ -396,7 +405,7 @@ containing two integers: \mintinline{python}{numerator} and \mintinline{python}{denominator}. \begin{itemize} -\item add, subtract; +\item add, subtract, e.g., $\frac{1}{2} + \frac{2}{3} = \frac{7}{6}$; \item print representation, convert to \mintinline{python}{float}; \item invert a fraction; \item $\ldots$ @@ -404,7 +413,8 @@ containing two integers: \mintinline{python}{numerator} and \bigskip -see: \path{https://github.com/lumc-python/oop} +see: \path{https://github.com/lumc-python/oop} \\ +or go directly to: \textcolor{pms280_compl}{\path{https://classroom.github.com/a/8BnbL9fD}} \end{frame} \end{document}