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

----
DocumentBuilder builder = new DocumentBuilderImpl();  // Noncompliant
----


== Compliant Solution

----
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

----


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
