
In some cases, the `rule.adoc` at root of a rule is never included anywhere and thus is dead code. It's a maintenance cost by itself, but also it misses opportunities to inline code that seems used by two documents when in fact only one document is actually rendered. And this missed opportunity, in turn, stops us from applying the correct language tag on the code samples.
69 lines
1.6 KiB
Plaintext
69 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
||
|
||
The difference between ``++private++`` and ``++protected++`` visibility is that child classes can see and use ``++protected++`` members, but they cannot see ``++private++`` ones. Since a ``++final++`` class will have no children, marking the members of a ``++final++`` class ``++protected++`` is confusingly pointless.
|
||
|
||
|
||
Note that the ``++protected++`` members of a class can also be seen and used by other classes that are placed within the same package, this could lead to accidental, unintended access to otherwise private members.
|
||
|
||
|
||
=== Noncompliant code example
|
||
|
||
[source,java]
|
||
----
|
||
public final class MyFinalClass {
|
||
|
||
protected String name = "Fred"; // Noncompliant
|
||
protected void setName(String name) { // Noncompliant
|
||
// ...
|
||
}
|
||
----
|
||
|
||
|
||
=== Compliant solution
|
||
|
||
[source,java]
|
||
----
|
||
public final class MyFinalClass {
|
||
|
||
private String name = "Fred";
|
||
public void setName(String name) {
|
||
// ...
|
||
}
|
||
----
|
||
|
||
|
||
=== Exceptions
|
||
|
||
Members annotated with ``++@VisibleForTesting++`` annotation are ignored, as it indicates that visibility has been purposely relaxed to make the code testable.
|
||
|
||
[source,java]
|
||
----
|
||
public final class MyFinalClass {
|
||
@VisibleForTesting
|
||
protected Logger logger; // Compliant
|
||
|
||
@VisibleForTesting
|
||
protected int calculateSomethingComplex(String input) { // Compliant
|
||
// ...
|
||
}
|
||
}
|
||
----
|
||
|
||
ifdef::env-github,rspecator-view[]
|
||
|
||
'''
|
||
== Implementation Specification
|
||
(visible only on this page)
|
||
|
||
include::../message.adoc[]
|
||
|
||
include::../highlighting.adoc[]
|
||
|
||
'''
|
||
== Comments And Links
|
||
(visible only on this page)
|
||
|
||
include::../comments-and-links.adoc[]
|
||
|
||
endif::env-github,rspecator-view[]
|