diff --git a/Lectures/L16_MISContinued/500px-AdapterPatternForWiki.jpg b/Lectures/L16_MISContinued/500px-AdapterPatternForWiki.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ab9d5b4b91f8d3661d708be55268a86a4187863e Binary files /dev/null and b/Lectures/L16_MISContinued/500px-AdapterPatternForWiki.jpg differ diff --git a/Lectures/L16_MISContinued/MISContinued.pdf b/Lectures/L16_MISContinued/MISContinued.pdf index fabfe21b1b4bab849e559b46b52d562b417abadf..da959a85ebc3a248510668b85e3d12c4d50c19b5 100644 Binary files a/Lectures/L16_MISContinued/MISContinued.pdf and b/Lectures/L16_MISContinued/MISContinued.pdf differ diff --git a/Lectures/L16_MISContinued/MISContinued.tex b/Lectures/L16_MISContinued/MISContinued.tex index ff2b083a07cb4a45dbeb301226689013ea383b67..e6648f47a814d8e03a0ec3b96a15ca1654478f7c 100755 --- a/Lectures/L16_MISContinued/MISContinued.tex +++ b/Lectures/L16_MISContinued/MISContinued.tex @@ -95,6 +95,24 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Emphasis} +\begin{itemize} +\item Math notation +\item Modules with external interaction (environment variables) +\item Types of modules +\item Abstract Data Types +\item Qualities of an interface +\item Design patterns +\begin{itemize} + \item Adapter (Wrapper) pattern + \item Strategy pattern +\end{itemize} +\end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % \begin{frame} % \frametitle{Nonfunctional Requirements} % \begin{itemize} @@ -1085,6 +1103,217 @@ where $a$, $b$ and $c$ are suitable constants %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Design Patterns} + +\begin{itemize} + +\item Christopher Alexander (1977, buildings/towns): +\begin{itemize} +\item ``Each pattern describes a problem which occurs over and over again in our + environment, and then describes the core of the solution to that problem, in + such a way that you can use this solution a million times over, without ever + doing it the same way.'' +\end{itemize} +\item Design reuse (intended for OO) +\item Solution for recurring problems +\item Transferring knowledge from expert to novice +%\item Provides language for communicating about design +\item A design pattern is a recurring structure of communicating components that + solves a general design problem within a particular context +\item Design patterns consist of multiple modules, but they do not constitute an + entire system architecture +\end{itemize} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Adapter Design Pattern} + +\includegraphics[scale=0.7]{500px-AdapterPatternForWiki.jpg} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Adapter UML Diagram} +% client uses target (follows targets interface) +% client, adapter and adaptee appear as in previous slide +\medskip +\includegraphics[scale=0.7]{adapter_clip.pdf} + +\href{https://en.wikipedia.org/wiki/Adapter_pattern} +{Wikipedia entry} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{SimUDuck Example} + +\bigskip + +\includegraphics[scale=0.74]{StratPat-SimUDuck.pdf} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Adding a Fly Method} + +\bigskip + +\includegraphics[scale=0.85]{StratPat-FlyMethod.pdf} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Rubber Duck Problem} + +\includegraphics[scale=0.7]{StratPat-RubberDuck.pdf} + +\structure{How to stop rubber ducks from flying?} %override to do nothing + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Rubber Duck Problem Continued} + +\bi +\item Solve problem by overriding the fly() method to do nothing +\item Not a good solution - think of the potential maintenance problems if we + add wooden decoys, which cannot fly, or quack - what about different quacks? +\ei + +Which of the following are disadvantages of using inheritance to provide Duck +behaviour? + +\begin{enumerate}[A.] +\item Some code is duplicated across subclasses +\item Runtime behaviour changes are difficult +\item Difficult to gain knowledge of all duck behaviours +\item Changes can unintentionally affect other ducks +\item All of the above %answer +\end{enumerate} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{How About an Interface?} + +\includegraphics[scale=0.75]{StratPat-Interface.pdf} + +Disadvantages of interface? + +\begin{enumerate}[A.] +\item Maintenance nightmare - the different options for fly and quack are + duplicated everywhere %answer +\item Ducks that have fly and quack are clearly shown +\item All of the above +\end{enumerate} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Information Hiding} + +How can the principle of information hiding help us? + +\begin{enumerate}[A.] +\item Identify the aspects of the application that are likely to change and + separate them from what is unlikely to change +\item Provide a means for part of the system to vary independently of the other + parts +\item Prevent the program's user from knowing which ducks can fly and/or quack +\item A and B %answer +\item A, B and C +\end{enumerate} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Separate Out Changeable Parts (Likely Changes)} + +\bigskip + +\includegraphics[scale=0.85]{StratPat-DuckBehaviours.pdf} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Implementing the Duck Behaviours} + +\bigskip + +\includegraphics[scale=0.66]{StratPat-ImpDuckBehaviours.pdf} + +\bi +\item Program to an interface not an implementation (interface in the sense we have +used it for MISes, not just a Java interface) +\item Other modules can use these behaviours too +\item Can add new behaviours without touching the original Duck class +\ei +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{The Big Picture} + +\bigskip + +\includegraphics[scale=0.66]{StratPat-BigPicture.pdf} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Often Favour Composition over Inheritance} + +\bi +\item Composition provides a ``has a'' relationship, as opposed to an ``is a'' + relationship +\item Composition provides greater flexibility +\item Composition allows changing behaviour at runtime +\item Many languages (like Java) do not allow multiple inheritance, but can have + multiple compositions +\ei + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame} +\frametitle{Strategy Pattern} + +Defines a family of algorithms, encapsulates each one, and makes them +interchangeable. Strategy lets the algorithm vary independently from the +clients that use it. + +\includegraphics[scale=0.6]{Strategy1.png} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame}[allowframebreaks] \frametitle{References} diff --git a/Lectures/L16_MISContinued/StratPat-BigPicture.pdf b/Lectures/L16_MISContinued/StratPat-BigPicture.pdf new file mode 100644 index 0000000000000000000000000000000000000000..7dfb853f9fb62061fa1a60a1660788b491350b79 Binary files /dev/null and b/Lectures/L16_MISContinued/StratPat-BigPicture.pdf differ diff --git a/Lectures/L16_MISContinued/StratPat-DuckBehaviours.pdf b/Lectures/L16_MISContinued/StratPat-DuckBehaviours.pdf new file mode 100644 index 0000000000000000000000000000000000000000..2264ee10170141ac011d248b5aab01a08dc7dba1 Binary files /dev/null and b/Lectures/L16_MISContinued/StratPat-DuckBehaviours.pdf differ diff --git a/Lectures/L16_MISContinued/StratPat-FlyMethod.pdf b/Lectures/L16_MISContinued/StratPat-FlyMethod.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4be3ce922f42ff4709a22ee24c54a03d64f998c9 Binary files /dev/null and b/Lectures/L16_MISContinued/StratPat-FlyMethod.pdf differ diff --git a/Lectures/L16_MISContinued/StratPat-ImpDuckBehaviours.pdf b/Lectures/L16_MISContinued/StratPat-ImpDuckBehaviours.pdf new file mode 100644 index 0000000000000000000000000000000000000000..87b056ab4813db738b4122e600823fe64c92cd49 Binary files /dev/null and b/Lectures/L16_MISContinued/StratPat-ImpDuckBehaviours.pdf differ diff --git a/Lectures/L16_MISContinued/StratPat-Interface.pdf b/Lectures/L16_MISContinued/StratPat-Interface.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c286fb388c0b4f587489ee9813ed103e8e90c306 Binary files /dev/null and b/Lectures/L16_MISContinued/StratPat-Interface.pdf differ diff --git a/Lectures/L16_MISContinued/StratPat-RubberDuck.pdf b/Lectures/L16_MISContinued/StratPat-RubberDuck.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c4d2b273079909e273edd14297ae84d96989d70e Binary files /dev/null and b/Lectures/L16_MISContinued/StratPat-RubberDuck.pdf differ diff --git a/Lectures/L16_MISContinued/StratPat-SimUDuck.pdf b/Lectures/L16_MISContinued/StratPat-SimUDuck.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4bb39719f3b7a72e6c8eb5a135142b1c75412a70 Binary files /dev/null and b/Lectures/L16_MISContinued/StratPat-SimUDuck.pdf differ diff --git a/Lectures/L16_MISContinued/Strategy1.png b/Lectures/L16_MISContinued/Strategy1.png new file mode 100644 index 0000000000000000000000000000000000000000..7a0a476a157b26f31ed7f9358d7f97175280dbfc Binary files /dev/null and b/Lectures/L16_MISContinued/Strategy1.png differ diff --git a/Lectures/L16_MISContinued/adapter_clip.pdf b/Lectures/L16_MISContinued/adapter_clip.pdf new file mode 100644 index 0000000000000000000000000000000000000000..eee75f4fe7bf7fe26ac08364df45f03d48973d8d Binary files /dev/null and b/Lectures/L16_MISContinued/adapter_clip.pdf differ