28 lines
711 B
Plaintext
28 lines
711 B
Plaintext
![]() |
The difference between <code>private</code> and <code>protected</code> visibility is that child classes can see and use <code>protected</code> members, but they cannot see <code>private</code> ones. Since a <code>sealed</code> class cannot have children, marking its members <code>protected</code> is confusingly pointless.
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
public sealed class MySealedClass
|
||
|
{
|
||
|
protected string name = "Fred"; // Noncompliant
|
||
|
protected void SetName(string name) // Noncompliant
|
||
|
{
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
public sealed class MySealedClass
|
||
|
{
|
||
|
private string name = "Fred";
|
||
|
public void SetName(string name)
|
||
|
{
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
----
|