\documentclass{article}
\usepackage{ulem}
\pagestyle{headings}
\begin{document}
\part{ Instantiate Application Object Refactoring}
This is a refactoring.  It is informed by some experience, but is by no means complete.

\section{ Intent}
Remove coupling with global state to make application reusable in different contexts.

\section{ Motivation}
\begin{itemize}
\item{Allows for subclassing applications, which benefits testing}
\item{Provides for multiple, differently-configured applications, desirable for virtual hosting environments}
\item{Aesthetics, ease of understanding}
\end{itemize}
\section{ Mechanics}
Presuming you are working on an app named "flarg":

\renewcommand{\labelenumi}{\arabic{enumi}}
\begin{enumerate}
\item{If there is a global \texttt{\$flarg} variable which is an instance of some kind of driver, rename it to \texttt{\$flarg\_driver}}
\item{In \texttt{lib/base.php}, create a global \texttt{\$flarg} which is an instance of \texttt{Flarg::}}
\item{For each static method in \texttt{Flarg::}}
\renewcommand{\labelenumi}{\arabic{enumii}}
\begin{enumerate}
\item{Find all calls of the method and replace \texttt{Flarg::method()} with \texttt{\$flarg->method()}.  (\textbf{Possible exception:} if the method is truly static, meaning it will always produce the same output given the same parameters, you might want to keep it static.)}
\end{enumerate}
\item{For each global variable (\texttt{\$flarg\_driver} is used as an example):}
\renewcommand{\labelenumi}{\arabic{enumii}}
\begin{enumerate}
\item{Add a \texttt{getDriver()} method to \texttt{Flarg::}}
\item{Make \texttt{getDriver()} return the global variable's value}
\item{Find references to the global variable, and replace each with a call to \texttt{\$flarg->getDriver()}}
\item{When all references are replaced, do \textbf{one} of the following:}
\renewcommand{\labelenumi}{\arabic{enumiii}}
\begin{enumerate}
\item{Move initialization code for the value into the method}
\item{Introduce a field, move initialization code into constructor}
\item{Introduce a field which defaults to \texttt{null}, move initialization code into getter, but only execute when the field is \texttt{null} (Note, beware of introducing cycles.)}
\end{enumerate}
\end{enumerate}
\end{enumerate}
When application class gets too heavy to work with, you can use ExtractClass\footnote{http://example.com/index.php?page=ExtractClass} and/or MoveMethod\footnote{http://example.com/index.php?page=MoveMethod} to split up responsibilities.

Ideally, we will eventually end up with an application object which takes all configuration as constructor parameters, does all of the application's work (probably most via delegation - FacadePattern\footnote{http://example.com/index.php?page=FacadePattern}), but does not contain any UI code.  Ideal for use from command-line scripts and unit tests.

\section{ TODO}
\renewcommand{\labelenumi}{\arabic{enumi}}
\begin{enumerate}
\item{Open discussion from Horde developers}
\item{Check for core developer support for this pattern.}
\item{When/how to write tests and run tests for this refactoring?}
\item{"Motivation" section needs some work.}
\item{\ldots}
\end{enumerate}
\end{document}
