diff --git a/analysis.xml b/analysis.xml index 8e4225a..1a327a8 100644 --- a/analysis.xml +++ b/analysis.xml @@ -4,7 +4,6 @@ - @@ -72,7 +71,6 @@ - @@ -292,20 +290,6 @@ - - - - - - - - - - - - - - @@ -321,6 +305,7 @@ + @@ -356,53 +341,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/report.pdf b/report.pdf index 1d1e160..f6f211c 100644 Binary files a/report.pdf and b/report.pdf differ diff --git a/report.tex b/report.tex index 27c3349..b19e524 100644 --- a/report.tex +++ b/report.tex @@ -2,8 +2,28 @@ \documentclass[12pt,a4paper]{scrartcl} \usepackage[utf8]{inputenc} -\usepackage[margin=2cm]{geometry} +\usepackage[margin=2.5cm]{geometry} \usepackage{hyperref} +\usepackage{listings} +\usepackage{xcolor} +\usepackage{lmodern} +\usepackage{listings} +\setlength{\parindent}{0cm} + +\lstset{ + basicstyle=\small\ttfamily, + %frame=shadowbox, + rulesepcolor=\color{black}, + columns=fullflexible, + commentstyle=\color{gray}, + keywordstyle=\color{blue}, + mathescape=true, + aboveskip=1em, + captionpos=b, + abovecaptionskip=1em, + belowcaptionskip=1em +} + \title{Assginment 1 -- Software Design and Modelling} @@ -174,7 +194,50 @@ TBD TBD \subsection{Template Method Pattern} -TBD +Due to the extendibility of Jackson, it is of no surprise that the template +method pattern is used extensively to create a class hierarchy that provides +rich interfaces while maintaining behavioural flexibility. \textit{Pattern4} +correctly detects several instances of the pattern, namely +\textbf{JsonStreamContext}, \textbf{JsonGenerator}, \textbf{type.ResolvedType}, +\textbf{JsonParser}, \textbf{base.ParserBase}, \textbf{base.GeneratorBase}, +\textbf{base.ParserMinimalBase}. All these classes implement several concrete +\texttt{public} methods throwgh the use of \texttt{protected abstract} methods. +Although the concrete (i.e. the template) methods are usually not vary complex +(as the pattern example shown in class), they still follow the principles of the +template method pattern. We show as an example some template methods found in +\textbf{base.ParserBase}: + +\begin{lstlisting}[caption=Template method \texttt{void close()} and step +methods \texttt{void \_closeInput()} and \texttt{void \_releaseBuffers()} in +\textbf{base.ParserBase}., language=java] +@Override public void close() throws IOException { + if (!_closed) { + // 19-Jan-2018, tatu: as per [core#440] need to ensure no more data + // assumed available + _inputPtr = Math.max(_inputPtr, _inputEnd); + _closed = true; + try { + _closeInput(); + } finally { + // as per [JACKSON-324], do in finally block + // Also, internal buffer(s) can now be released as well + _releaseBuffers(); + } + } +} + +protected abstract void _closeInput() throws IOException; + +protected void _releaseBuffers() throws IOException { + /* implementation omitted */ +} +\end{lstlisting} + +Here the pattern is slightly modified by providing a default implementation of +\texttt{void \_releaseBuffers()}. In this case, child classes occasionally +override the method with a body first calling \texttt{super()} and then adding +additional buffer release code after. + \subsection{Visitor Pattern} TBD