rspec/rules/S2974/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

66 lines
1.4 KiB
Plaintext

== Why is this an issue?
Classes with only ``++private++`` constructors should be marked ``++final++`` to prevent any mistaken extension attempts.
=== Noncompliant code example
[source,java]
----
public class PrivateConstructorClass { // Noncompliant
private PrivateConstructorClass() {
// ...
}
public static int magic(){
return 42;
}
}
----
=== Compliant solution
[source,java]
----
public final class PrivateConstructorClass { // Compliant
private PrivateConstructorClass() {
// ...
}
public static int magic(){
return 42;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make this class "final" or add a public constructor.
'''
== Comments And Links
(visible only on this page)
=== on 27 May 2015, 08:42:14 Freddy Mallet wrote:
My personal feedback:
* I would not activate this rule by default as it is controversial -> some guys are going to say that it's useless to flag such classes as final as any way it's by design not possible to extend them
* Due to the previous point I would associate this rule to the SQALE characteristic "Maintainability > Understandability" and not "Changeability - Architecture related changeability"
=== on 27 May 2015, 19:16:27 Ann Campbell wrote:
Rule updated
=== on 1 Jun 2015, 13:06:32 Nicolas Peru wrote:
ok.
endif::env-github,rspecator-view[]