48 lines
1.0 KiB
Plaintext
48 lines
1.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The use of factory methods lets you abstract the job you need to do from the specific tool implementations needed to do it with, and helps insulate you from changes.
|
|
|
|
|
|
This rule raises an issue when instances of these are instantiated directly:
|
|
|
|
* ``++javax.xml.parsers.DocumentBuilder++``
|
|
* ``++javax.xml.parsers.SAXParser++``
|
|
* ``++javax.xml.transform.Transformer++``
|
|
* ``++org.xml.sax.XMLReader++``
|
|
* ``++org.xml.sax.XMLFilter++``
|
|
* ``++org.w3c.dom.*++``
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
DocumentBuilder builder = new DocumentBuilderImpl(); // Noncompliant
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|