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}
None found
\subsection{Strategy Pattern}
None found
\subsection{State Pattern}
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
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}
\item[util.DefaultPrettyPrinter] false positive, strategy pattern;
\item[JsonFactory] false positive, \textit{InputDecorator \_inputDecorator},
\textit{OutputDecorator \_outputDecorator}, \textit{SerializedString
\_rootValueSeparator} are strategy instances (more
specifically a way to pre-process input before Jackson parses it, labeled as
``decorator'' by Jackson developers but not really a decorator pattern
application since InputDecorator is not a subclass of any component to
decorate);
\item[json.WriterBasedJsonGenerator] false positive,
\textit{SerializableString \_currentEscape} is a simple \textit{String}-like
object that gets updated based on the parsing state.
\item[util.DefaultPrettyPrinter] ??? WIP
\item[util.DefaultPrettyPrinter \textit{\_inputDecorator} and
\textit{\_outputDecorator}] are fields flagged as states, thus flagging the
class as a state pattern instance. However, no ``state'' akin to a
finite-state machine is maintained by the class to determine which
implementation of these fields to invoke. What is detected are more likely
lightweight implementations of the strategy pattern, since these fields can
be mutated through matching getters and setters. Additionally, the
documentation of each of the matching \textit{...Decorator} field types
(namely interfaces) states that implementors are meant to be algorithms to
pre-process input before the formatting process (a feature labeled as
``decorator'' w.r.t.\ the library, not to be confused with the decorator
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}
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}
Due to the extendibility of Jackson, it is of no surprise that the template