diff --git a/Lectures/L12_OOD/OOD.pdf b/Lectures/L12_OOD/OOD.pdf index 321063afd037b35a75fafc6d5f06769424db6e8e..b15a3bf6a831e34e7f7c98310618f77035760029 100644 Binary files a/Lectures/L12_OOD/OOD.pdf and b/Lectures/L12_OOD/OOD.pdf differ diff --git a/Lectures/L12_OOD/OOD.tex b/Lectures/L12_OOD/OOD.tex index be26f3bf8593fa7daabac2d1fe2aa6b46bfc8299..37f96386e0e1d6a1d555dd7efbc3cc03162ca1ca 100755 --- a/Lectures/L12_OOD/OOD.tex +++ b/Lectures/L12_OOD/OOD.tex @@ -11,6 +11,8 @@ unicode=false} \urlstyle{same} +\usepackage{listings} + \usepackage{booktabs} \useoutertheme{split} %so the footline can be seen, without needing pgfpages @@ -21,7 +23,7 @@ \mode<presentation>{} \input{../def-beamer} -\Drafttrue +\Draftfalse \newcommand{\topicTitle}{12 Object Oriented Design (Ghezzi Ch.\ 4)} \ifDraft @@ -36,6 +38,9 @@ \input{../footline} +\lstset{language=python, breaklines=true, showspaces=false, + showstringspaces=false, breakatwhitespace=true, texcl=true, escapeinside={\%*}{*)}} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} @@ -61,21 +66,11 @@ TBD \else { \begin{itemize} -\item NSERC Undergraduate Student Research Award \item Assignment 1 \begin{itemize} -\item E-mail your partner if you haven't already done so -\item E-mail the instructor if you haven't received your partner's code -\item Lab report due by 11:59 pm February 2 -\end{itemize} - -\item Assignment 2 -\begin{itemize} -\item Files due by 11:59 pm Feb 15 -\item E-mail partner files by 11:59 pm Feb 16 -\item Lab report due by 11:59 pm Feb 27 +\item Part 2: January 31, 2018 \end{itemize} - +\item Questions? \end{itemize} } \fi @@ -94,13 +89,119 @@ TBD to review changes between commits \item Review before committing: \texttt{git difftool} \item To better deal with changes, use a ``hard wrap'' at an 80 column width, - even for LaTeX documents + even for LaTeX documents (\structure{why?}) \end{itemize} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Set Idiom (H\&S)} + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +set\_add & T & ~ & Member, Full\\ +\hline +set\_del & T & ~ & NotMember\\ +\hline +set\_member & T & boolean & ~\\ +\hline +set\_size & ~ & integer & ~\\ +\hline +\end{tabular} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Sequence Idiom (H\&S)} + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +seq\_init & ~ & ~ & ~\\ +\hline +seq\_add & integer, T & ~ & PosOutOfRange, Full\\ +\hline +seq\_del & integer & ~ & PosOutOfRange\\ +\hline +seq\_setval & integer, T & ~ & PosOutOfRange\\ +\hline +seq\_getval & integer & T & PosOutOfRange\\ +\hline +seq\_size & ~ & integer & ~\\ +\hline +seq\_start & ~ & ~ & ~\\ +\hline +seq\_next & ~ & T & AtEnd\\ +\hline +seq\_end & ~ & boolean & ~\\ +\hline +seq\_append & T & ~ & Full\\ +\hline +\end{tabular}\\ +~\\ +\structure<1>{When would you use seq\_next in the interface, and exclude + seq\_getval?} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Tuple Idiom Version 1 (H\&S)} + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +tp\_init & ~ & ~ & ~\\ +\hline +tp\_set\_f$_1$ & T$_1$ & ~ & ~\\ +\hline +tp\_get\_f$_1$ & ~ & T$_1$ & ~\\ +\hline +... & ... & ... & ...\\ +\hline +tp\_set\_f$_N$ & T$_N$ & ~ & ~\\ +\hline +tp\_get\_f$_N$ & ~ & T$_N$ & ~\\ +\hline +\end{tabular}\\ +~\\ +\structure{What is a potential problem with this idiom, especially if there are + many fields to the tuple?} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} + +\frametitle{Tuple Idiom Version 2 (H\&S)} + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +tp\_init & ~ & ~ & ~\\ +\hline +tp\_set & T$_1$, T$_2$, ..., T$_N$ & ~ & ~\\ +\hline +tp\_get & ~ & T & ~\\ +\hline + +\end{tabular} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame} \frametitle{Object Oriented Design} \begin{itemize} @@ -126,6 +227,13 @@ TBD \item A is a superclass of B \item B is a subclass of A \end{itemize} +~\\ +\structure<1>{In Python, what class do all classes inherit?}\\ %object +~\\ +\structure<2>{What method inherited from object did we recently override?}\\ + % __eq__ +~\\ + \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -196,14 +304,18 @@ def\_skill & skillT & ~ & ~\\ \begin{itemize} \item A way of building software incrementally -\item Useful for long lived applications because new features can be added without breaking the old applications +\item Useful for long lived applications because new features can be added + without breaking the old applications \item A subclass defines a subtype \item A subtype is substitutable for the parent type -\item Polymorphism - a variable referring to type A can refer to an object of type B if B is a subclass of A -\item Dynamic binding - the method invoked through a reference depends on the type of the object associated with the -reference at runtime -\item All instances of the sub-class are instances of the super-class, so the type of the sub-class is a subtype -\item All instances of Administrative\_Staff and Technical\_Staff are instances of Employee +\item Polymorphism - a variable referring to type A can refer to an object of + type B if B is a subclass of A +\item Dynamic binding - the method invoked through a reference depends on the + type of the object associated with the reference at runtime +\item All instances of the sub-class are instances of the super-class, so the + type of the sub-class is a subtype +\item All instances of Administrative\_Staff and Technical\_Staff are instances + of Employee \end{itemize} \end{frame} @@ -214,7 +326,10 @@ reference at runtime emp1, emp2: Employee\\ emp3: Technical\_Staff\\ - +~\\ +\structure<1>{What assignments are allowed? That is, where would polymorphism + allow us to switch references to the RHS with what appears on the LHS?}\\ +~\\ emp1 = Administrative\_Staff() \uncover<2->{\structure{$\surd$}}\\ emp2 = Technical\_Staff() \uncover<3->{\structure{$\surd$}}\\ emp3 = emp1 \uncover<4->{\structure{$\times$}}\\ @@ -249,8 +364,10 @@ emp3 = (Technical\_Staff) emp1 \uncover<5->{\structure{$\surd$}}\\ \item UML (Unified Modelling Language) is a widely adopted standard notation for representing OO designs \item We introduce the UML class diagram \item Classes are described by boxes - \end{itemize} + +\structure{Any guesses on what Parnas said UML stood for?} %Undefined Modelling Language + \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -275,6 +392,20 @@ emp3 = (Technical\_Staff) emp1 \uncover<5->{\structure{$\surd$}}\\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Class Diagram Versus MIS} + +\begin{itemize} +\item \structure<1>{What information do the MIS and Class Diagram have in common?} +\item \structure<2>{What information does the MIS add?} %semantics +\item \structure<3>{What information does the Class Diagram add?} %richer set of + %uses relations +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame} \frametitle{UML Associations} @@ -409,7 +540,7 @@ PointMassT = ?\\ \hline \textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ \hline -new PointMassT & real, real, real & PointMassT & NegMassException\\ +new PointMassT & real, real, real & PointMassT & NegMassExcept\\ \hline mval & ~ & real & ~\\ \hline @@ -437,7 +568,7 @@ $ms$: real \begin{itemize} \item transition: $xc, yc, ms := x, y, m$ \item output: $out := \mathit{self}$ -\item exception: $exc := (m < 0 \Rightarrow \mbox{NegativeMassException})$ +\item exception: $exc := (m < 0 \Rightarrow \mbox{NegMassExcept})$ \end{itemize} ~\newline \noindent force($p$):