rspec/rules/S2974/java/rule.adoc

66 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Classes with only ``++private++`` constructors should be marked ``++final++`` to prevent any mistaken extension attempts.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class PrivateConstructorClass { // Noncompliant
private PrivateConstructorClass() {
// ...
}
public static int magic(){
return 42;
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
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[]