Are Refactoring Tools Doing
Pattern Automation?
It could be argued that refactorings Fowler (1999) are related to and in some
cases similar to Patterns. They encapsulate proven ‘moves’ in the chess game
of refactoring code. Some refactorings go so far as to encapsulate proven
designs e.g. ‘Change Unidirectional Association to Bidirectional’, (p200,
Refactoring) show the best way to implement a bidirectional association.
Similarly, ‘Duplicate Observed Data’ (p 189, Refactoring) shows how to
implement the Observer Pattern.
Source code editors with refactoring support are becoming more popular and
moving from their original use in Smalltalk circles to the more mainstream
Java community, more recently to the Python community and beyond.
Figure 6: Examples of refactoring editors and refactoring tools that plug
into existing IDE’s. Clockwise from the top - Jrefactory plug-in, Eclipse,
IntelliJ.
In fact a designer may encounter situations where none of the sample implementations offered in the design pattern
document are suitable to the designer’s particular situation, or possible to implement in the implementation language
available (e.g. it may be a non-object oriented language). In these cases the designer will need to invent a custom
solution based solely on the ideas discussed in the design pattern document.
Thus the idea of automating this entire complex process can therefore seem ludicrous, given the amount of design,
human thought, and customization of solution structures often (or perhaps always?) required.
4.1 What aspect of patterns
should be automated
The rebuttal to the objection that
“pattern automation should not be
attempted at all” is to be found in
distinguishing exactly what aspect
of design pattern process software
tools are really trying to automate.
Are they really trying to replace
the designer’s deliberations or
merely assisting the designer in the
mundane and often complex task
of implementing the pattern?
The tools so far described in fact
do not replace the designer’s
deliberations in choosing which
pattern to use at any given time.
The tools do not replace the need
for the designer to understand how
and why he or she is using a
particular pattern. Nor do the tools
replace the need for the designer to
understand the balance of forces
and trade-offs involved in
choosing different solution
variations.
Once the designer has decided
what sort of pattern solution is
required, then what the pattern
automation tools can help him or
her with, is the moderately
complex and careful surgery
required to implement that pattern
solution into a UML diagram or
into source code.
4.2 Fitting the pattern to
the problem
Gamma et. al (1993) say in Design
Patterns, p. 3: “Design Patterns
are not about designs such as
linked lists and hash tables that can
be encoded in classes and reused as is. Nor are they complex, domain-specific designs for an entire application or
subsystem. The design patterns in this book are descriptions of communicating objects and classes that are customized
to solve a general design problem in a particular context.”
Thus an important argument against the idea of automating pattern ‘implementations’ is that by the time the design
process has considered all the forces in the designer’s context and the designer has adapted the pattern solution to fit his
or her unique situation, then the implementation stage will involve coding up something that is quite unique. Pattern
automation tools that offer out of the box solution structures are unlikely to ever match what the designer really wants -
even when you take into account the customisation features of the tool.
The problem of fitting the automated pattern templates to the exact problem at hand might in principle always be a
mismatch in the sense that say, hand crafted solutions might always be better. A custom tailored suit is always going to