rspec/rules/S3398/rule.adoc

43 lines
724 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
When a ``++private++`` method is only invoked by an inner class, there's no reason not to move it into that class. It will still have the same access to the outer class' members, but the outer class will be clearer and less cluttered.
2020-06-30 12:48:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
public class Outie {
private int i=0;
private void increment() { // Noncompliant
i++;
}
public class Innie {
public void doTheThing() {
Outie.this.increment();
}
}
}
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
public class Outie {
private int i=0;
public class Innie {
public void doTheThing() {
increment();
}
private void increment() {
Outie.this.i++;
}
}
}
----