strategy and state pattern done

This commit is contained in:
Claudio Maggioni 2022-10-19 17:25:51 +02:00
parent cd44440bbf
commit bbf3df6192
2 changed files with 30 additions and 15 deletions

Binary file not shown.

View file

@ -206,8 +206,6 @@ None found
\subsection{Observer Pattern} \subsection{Observer Pattern}
None found None found
\subsection{Strategy Pattern}
None found
\subsection{State Pattern} \subsection{State Pattern}
Among the design patterns \textit{Pattern4J} detects, the state pattern is Among the design patterns \textit{Pattern4J} detects, the state pattern is
@ -217,22 +215,39 @@ state of a finite state machine the context class implements. In other words,
the state pattern chooses the concrete strategy to use through the state of the the state pattern chooses the concrete strategy to use through the state of the
context. context.
By analyzing the \textit{Pattern4J} results and the code, we can say that all
the instances of the state pattern the tool finds are false positives. Namely:
\begin{description} \begin{description}
\item[util.DefaultPrettyPrinter] false positive, strategy pattern; \item[util.DefaultPrettyPrinter \textit{\_inputDecorator} and
\item[JsonFactory] false positive, \textit{InputDecorator \_inputDecorator}, \textit{\_outputDecorator}] are fields flagged as states, thus flagging the
\textit{OutputDecorator \_outputDecorator}, \textit{SerializedString class as a state pattern instance. However, no ``state'' akin to a
\_rootValueSeparator} are strategy instances (more finite-state machine is maintained by the class to determine which
specifically a way to pre-process input before Jackson parses it, labeled as implementation of these fields to invoke. What is detected are more likely
``decorator'' by Jackson developers but not really a decorator pattern lightweight implementations of the strategy pattern, since these fields can
application since InputDecorator is not a subclass of any component to be mutated through matching getters and setters. Additionally, the
decorate); documentation of each of the matching \textit{...Decorator} field types
\item[json.WriterBasedJsonGenerator] false positive, (namely interfaces) states that implementors are meant to be algorithms to
\textit{SerializableString \_currentEscape} is a simple \textit{String}-like pre-process input before the formatting process (a feature labeled as
object that gets updated based on the parsing state. ``decorator'' w.r.t.\ the library, not to be confused with the decorator
\item[util.DefaultPrettyPrinter] ??? WIP pattern);
\item[util.DefaultPrettyPrinter \_objectIndenter and \_arrayIndenter] are
false positives too, and are likely strategy patterns too for the reasons
described above.
\item[util.DefaultPrettyPrinter \_rootValueSeparator] is flagged as a state
field too, however the field is simply a boxed \textit{String-like}
immutable data structure (i.e.\ \textit{SerializableString}) that is
swapped during the pretty-printer parsing logic;
\item[json.WriterBasedJsonGenerator \_currentEscape] is a false positive for
the same reasons described above.
\end{description} \end{description}
WIP instances and examples \subsection{Strategy Pattern}
\textit{Pattern4j} detects no instance of the strategy pattern in Jackson,
however the previous section regarding the state pattern referenced some false
positives that were indeed applications of this pattern. Due to the flexibility
of Jackson, there are many more instances of the strategy pattern to configure
and customize the serialization and deserialization pipeline in several stages.
\subsection{Template Method Pattern} \subsection{Template Method Pattern}
Due to the extendibility of Jackson, it is of no surprise that the template Due to the extendibility of Jackson, it is of no surprise that the template