-
Notifications
You must be signed in to change notification settings - Fork 222
/
S3398_c#.html
49 lines (44 loc) · 1.05 KB
/
S3398_c#.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<p>When a <code>private</code> 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.</p>
<h2>Noncompliant Code Example</h2>
<pre>
public class Outer
{
public void OuterMethod()
{
Console.WriteLine("Called from an outer method.");
}
private static void Print(int num) // Noncompliant - method is only used by inner class, should be moved there
{
Console.WriteLine(num);
}
public class Inner
{
public void SomeMethod()
{
Outer.Print(42);
}
}
}
</pre>
<h2>Compliant Solution</h2>
<pre>
public class Outer
{
public void OuterMethod()
{
Console.WriteLine("Called from an outer method.");
}
public class Inner
{
public void SomeMethod()
{
Print(42);
}
private static void Print(int num)
{
Console.WriteLine(num);
}
}
}
</pre>