rspec/rules/S3068/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

53 lines
1.1 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)
=== Message
Use a factory method to create this "xxx".
'''
== Comments And Links
(visible only on this page)
=== on 15 Jun 2015, 20:14:10 Nicolas Peru wrote:
Looks good
endif::env-github,rspecator-view[]