49 lines
1.0 KiB
Plaintext
49 lines
1.0 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 ``++sealed++`` class cannot have children, marking its members ``++protected++`` is confusingly pointless.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
public sealed class MySealedClass
|
|
{
|
|
protected string name = "Fred"; // Noncompliant
|
|
protected void SetName(string name) // Noncompliant
|
|
{
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
public sealed class MySealedClass
|
|
{
|
|
private string name = "Fred";
|
|
public void SetName(string name)
|
|
{
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
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[]
|