\documentclass[12pt]{article}
\usepackage{stmaryrd}
\usepackage{amsfonts, amssymb, amsmath, comment}
\usepackage{times}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{url}
\usepackage{xypic}
\usepackage{epsf}
\usepackage{epsfig}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
\usepackage{tikz-uml}
\usepackage{enumitem}

\setlist[itemize]{nosep}
\setlist[enumerate]{nosep}

\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{9.0in}
\setlength{\topmargin}{-0.5in}
\setlength{\headheight}{0in}
\parskip12pt
\parindent0pt
\pagestyle{fancy}
\lhead{CS 430 - Fall 2023}
\chead{CM A05}
\rhead{Due Friday, November 24, 11:59 PM EDT}
\cfoot{\normalfont\medskip Copyright \copyright 2023}

\newcommand{\rmp}{\reversemarginpar\marginpar}

\providecommand{\SolutionQuestionOOParadigm}{\vspace{6cm}}
\providecommand{\SolutionQuestionEncapsulation}{}
\providecommand{\SolutionQuestionAbstractDataTypesPartA}{\vspace{8cm}}
\providecommand{\SolutionQuestionAbstractDataTypesPartB}{}
\providecommand{\SolutionQuestionInheritance}{}
\providecommand{\SolutionQuestionDynamicBindingPartA}{\vspace{10cm}}
\providecommand{\SolutionQuestionDynamicBindingPartB}{\vspace{6cm}}
\providecommand{\SolutionQuestionDynamicBindingPartC}{}
\providecommand{\SolutionQuestionReUseTypes}{\vspace{10cm}}
\providecommand{\SolutionQuestionLibraryApplicationFrameworkPartA}{
\begin{center}
{\includegraphics[width=0.1\textwidth]{Re-Use-Diagram.png}}
\end{center}
\vspace{5cm}
}
\providecommand{\SolutionQuestionLibraryApplicationFrameworkPartB}{
\begin{center}
{\includegraphics[width=0.1\textwidth]{Re-Use-Diagram.png}}
\end{center}
\vspace{5cm}
}
\providecommand{\SolutionQuestionDesignPatternsPartA}{}
\providecommand{\SolutionQuestionDesignPatternsPartB}{\vspace{12cm}}
\providecommand{\SolutionQuestionDesignPatternsPartC}{}

\input xy
\xyoption{all}

\newtheorem{DefinitionPlaceHolder}{Definition}
\newtheorem{DefinitionAbstractDataType}[DefinitionPlaceHolder]{Definition}

\begin{document}

\begin{itemize}
\item{
Assignments must be completed individually.
}
\item{
No late assignments will be accepted.
}
\item{
Provide \textbf{concise} answers to the following questions.
Use \textbf{point form} whenever possible.
}
\item{
Submit your completed solutions to \textbf{Crowdmark}.
}
\end{itemize}

\begin{enumerate}

\item \label{QuestionOOParadigm}
The \rmp{[2]}Lecture Notes state that the OO paradigm is the best software development methodology invented so far.
However, it is still not perfect.
Briefly describe one problem associated with the use of the OO paradigm.
\SolutionQuestionOOParadigm

\item \label{QuestionEncapsulation}
Give \rmp{[4]}an example of a module which has \textbf{information hiding} but not \textbf{encapsulation}.
Briefly explain why your example is correct.
\SolutionQuestionEncapsulation

\newpage

\item \label{QuestionAbstractDataTypes}
\begin{enumerate}
\item \label{QuestionAbstractDataTypesPartA}
Briefly \rmp{[2]}explain the difference between
\begin{enumerate}[label=\roman*.]
\item{
a module having encapsulation, and
}
\item{
an \textbf{abstract data type}.
}
\end{enumerate}
\SolutionQuestionAbstractDataTypesPartA

\item \label{QuestionAbstractDataTypesPartB}
Give \rmp{[4]}an example of an abstract data type which is \textbf{not} one given in the text, the Lecture Notes or the Lecture Slides.
Briefly explain why your example is correct.
\SolutionQuestionAbstractDataTypesPartB
\end{enumerate}

\newpage

\item \label{QuestionInheritance}
Draw \rmp{[6]}a class diagram which displays the following classes and the relationships among them.
\begin{itemize}
\item{
\texttt{Vehicle}
\begin{itemize}
\item{
Properties:
\begin{itemize}
\item{
\texttt{modelName}
}
\item{
\texttt{manufactureDate}
}
\end{itemize}
}
\item{
Methods:
\begin{itemize}
\item{
\texttt{drive}
}
\item{
\texttt{park}
}
\end{itemize}
}
\end{itemize}
}
\item{
\texttt{Car} (a derived class of \texttt{Vehicle})
\begin{itemize}
\item{
Methods:
\begin{itemize}
\item{
\texttt{replaceBrakeFluid}
}
\end{itemize}
}
\end{itemize}
}
\item{
\texttt{Bicycle} (a derived class of \texttt{Vehicle})
\begin{itemize}
\item{
Methods:
\begin{itemize}
\item{
\texttt{replaceChain}
}
\end{itemize}
}
\end{itemize}
}
\end{itemize}
\SolutionQuestionInheritance

\newpage

\item{ \label{QuestionDynamicBinding}
\begin{enumerate}
\item
Provide \rmp{[3]}an example of \textbf{dynamic binding} which is \textbf{different} from the \texttt{Open} method of the \texttt{File} class given in the text and in the Lecture Notes and Lecture Slides.
\SolutionQuestionDynamicBindingPartA
\item
Dynamic \rmp{[2]}binding provides many advantages for programming.
However, it also has its shortcomings.
State two problems associated with the use of dynamic binding.
\SolutionQuestionDynamicBindingPartB
\item
Briefly \rmp{[2]}explain the difference between dynamic binding and polymorphism.
\SolutionQuestionDynamicBindingPartC
\end{enumerate}
}

\newpage

\item \label{QuestionReUseTypes}
At \rmp{[4]}the start of the discussion of Chapter 8 in the Lecture Notes, we identified two broad categories of software re-use.
Give the name of each category, together with one example of a situation in which it occurs which is \textbf{not} one given in the text, in the Lecture Notes or in the Lecture Slides.
\SolutionQuestionReUseTypes

\newpage

\item \label{QuestionLibraryApplicationFramework}
This problem is about \textbf{Library Re-use} (part a) and \textbf{Application Framework Re-use} (part b).
In each part,
\begin{enumerate}[label=\roman*.]
\item{
shade in the area in the given diagram that represents the part that \textbf{gets re-used} under the given scheme,
}
\item{
give the name of the re-used part (represented by the shaded area), and
}
\item{
give an example of this type of re-use.
}
\end{enumerate}
\begin{enumerate}
\item
Library \rmp{[3]}Re-use
\SolutionQuestionLibraryApplicationFrameworkPartA
\item
Application \rmp{[3]}Framework Re-use 
\SolutionQuestionLibraryApplicationFrameworkPartB
\end{enumerate}

%\end{enumerate}

\newpage

\item{ \label{QuestionDesignPatterns}
This question is about the \textbf{Memento design pattern}, which is on the list of the 23 patterns from which the text examples are chosen, but is not one of the patterns included in the text.
The pattern is described here.

\noindent
\textbf{Motivation:}
Sometimes it is necessary to record the internal state of an object.
This is required when implementing checkpoints and ``undo'' mechanisms, that let the user back out of tentative operations, or recover from errors.
You must save state information somewhere, so that you can restore the object to its previous state.
But an object typically hides some or all of its state, making it inaccessible to other objects, and thus impossible to save externally.
Exposing the state would violate the principle of information hiding.

\noindent
\textbf{Class Diagram:}

\begin{center}
\begin{tikzpicture}
\umlclass{Memento}{state}{
  GetState() \\
  SetState() \\
}
\umlclass[x=-5,y=-2]{Originator}{state}{
  SetMemento(Memento m) \\
  CreateMemento() \\
}
\umlclass[x=5,y=-2]{Caretaker}{}{}

\umldep[geometry=|-]{Originator}{Memento}
\umluniaggreg[geometry=|-]{Caretaker}{Memento}
\end{tikzpicture}\\
Notation: \xymatrix{ \ar@{-->}[r] &} for ``Creates'' and \xymatrix{ \ar@{->}[r] &} for ``References''.
\end{center}

\noindent
\textbf{Method Pseudocode}
\begin{enumerate}
\item{
\underline{\texttt{SetMemento(Memento m)}}\\
\texttt{state = m -> GetState()}
}
\item{
\underline{\texttt{CreateMemento()}}\\
\texttt{return new Memento(state)}
}
\end{enumerate}

\noindent
\textbf{Interaction Diagram}

\begin{center}
\begin{tikzpicture}
\begin{umlseqdiag}
\umlobject[no ddots]{aCaretaker}
\umlobject[no ddots]{anOriginator}
\umlobject[no ddots]{aMemento}
\begin{umlcall}[op=CreateMemento(), type=synchron]{aCaretaker}{anOriginator}
\begin{umlcall}[op=New Memento, type=return]{anOriginator}{aMemento}
\begin{umlcall}[op=SetState(), type=synchron]{anOriginator}{aMemento}
\end{umlcall}
\end{umlcall}
\end{umlcall}
\begin{umlcall}[op=SetMemento(aMemento), type=synchron]{aCaretaker}{anOriginator}
\begin{umlcall}[op=GetState(), type=synchron]{anOriginator}{aMemento}
\end{umlcall}
\end{umlcall}
\end{umlseqdiag}
\end{tikzpicture}
\end{center}

\begin{itemize}
\item{
A \texttt{Caretaker} requests a \texttt{Memento} from an \texttt{Originator}, holds it for a time, and passes it back to the \texttt{Originator}, as the diagram indicates.
}
\item{
Sometimes the \texttt{Caretaker} will not pass the \texttt{Memento} back to the \texttt{Originator}, because the \texttt{Originator} might never need to revert to an earlier state.
}
\item{
\texttt{Memento}s are passive.
Only the \texttt{Originator} that created a \texttt{Memento} will assign or retrieve its state.
}
\end{itemize}

\noindent
In this question, we will work with the Memento pattern applied to a Visio-like application, for creating diagrams via drag-and-drop.
To undo a move made by dragging a \texttt{Box}, we will use the \texttt{Memento} pattern to remember the original state of the \texttt{Box}, so that we can return the \texttt{Box} plus any incoming/outgoing arrows to their original positions.

\begin{enumerate}
\item
Draw \rmp{[5]}the class diagram for our application, in which
\begin{itemize}
\item{
\texttt{Originator} is replaced by \texttt{Box},
\begin{itemize}
\item{
\texttt{SetMemento(Memento m)} is replaced by \texttt{SetBoxState(BoxState s)},
}
\item{
\texttt{CreateMemento()} is replaced by \texttt{CreateBoxState()},
}
\end{itemize}
}
\item{
\texttt{Memento} is replaced by \texttt{BoxState}, and
}
\item{
\texttt{Caretaker} is replaced by \texttt{BoxUndo}.
}
\end{itemize}
\SolutionQuestionDesignPatternsPartA

\newpage

\item
Draw \rmp{[5]}the interaction diagram for our application, in which
\begin{itemize}
\item{
\texttt{anOriginator} is replaced by \texttt{aBox},
\begin{itemize}
\item{
\texttt{New Memento} is replaced by \texttt{New BoxState},
}
\item{
\texttt{SetMemento(aMemento)} is replaced by \texttt{SetBoxState(aBoxState)},
}
\item{
\texttt{CreateMemento()} is replaced by \texttt{CreateBoxState()},
}
\end{itemize}
}
\item{
\texttt{aMemento} is replaced by \texttt{aBoxState}, and
}
\item{
\texttt{aCaretaker} is replaced by \texttt{aBoxUndo}.
}
\end{itemize}
\SolutionQuestionDesignPatternsPartB

\item
The \rmp{[3]}primary motivation to use the Memento design pattern in this question is to preserve the \textbf{information hiding} of the \texttt{Box} object.
Give three reasons why information hiding is a desirable ingredient in effective object-oriented programming.
\SolutionQuestionDesignPatternsPartC

\end{enumerate}
}

\end{enumerate}

\end{document}