Java Reference
In-Depth Information
Split Cleaners
D
ESCRIPTION
:
When a resource is allocated separately from where it is
freed, cleanup can be lost.
M
OST
FREQUENT
SCALE
:
Application.
R
EFACTORED
SOLUTION
NAME
:
Pairing Connections with Cleanup.
R
EFACTORED
SOLUTION
TYPE
:
Software.
R
EFACTORED
SOLUTION
DESCRIPTION
:
Connections should be allocated
and cleared in close proximity, and
finally
blocks should be used for con-
nection cleanup. In this way, inspection will quickly show whether a con-
nection has been cleansed appropriately.
R
OOT
CAUSES
:
Haste, sloth.
A
NECDOTAL
EVIDENCE
:
“That connection probably gets cleaned up
somewhere else.”
S
YMPTOMS
,
CONSEQUENCES
:
Resources, like database or file connections,
run out prematurely.
Hardwired Connections
D
ESCRIPTION
:
For business-to-business connections, a common imple-
mentation is to enumerate all of the fields in an entire interface, complete
with parameter and return types. The connection is then made through
some form of a remote procedure call. This approach makes the connec-
tion difficult to maintain and support as the interfaces change.
M
OST
FREQUENT
SCALE
:
Enterprise.
R
EFACTORED
SOLUTION
NAME
:
Web services or
XML
messages.
R
EFACTORED
SOLUTION
TYPE
:
Software.
R
EFACTORED
SOLUTION
DESCRIPTION
:
Connections should be made
with common standards that allow a dynamic description of the transac-
tion, including the parameter set and the message construction. Web ser-
vices provide such a wrapping, through open standards, including
SOAP
for messaging and
XML
for the description of the parameter and message
format.
T
YPICAL
CAUSES
:
The solution described by this antipattern is actually
one of the most common implementations of business-to-business con-
nections. Many have not yet migrated to
XML
-based solutions for a variety
of reasons.