The following example shows a type that violates this rule.
|
Imports System
Namespace DesignLibrary
Public NotInheritable Class BadSealedType
Protected Sub MyMethod
End Sub
End Class
End Namespace
|
|
using System;
namespace DesignLibrary
{
public sealed class SealedClass
{
protected void ProtectedMethod(){}
}
}
|
The above sealed type declares a protected member, which cannot be called outside the class that declares it.
If the method was designed to be called by other types, increase its accessibility to public, otherwise, reduce its accessibility to private.
The following example fixes the above violation by increasing the method's accessibility to public.
|
Imports System
Namespace Samples
Public NotInheritable Class Book
Protected Sub Read
End Sub
End Class
End Namespace
|
|
using System;
namespace Samples
{
public sealed class Book
{
protected void Read()
{
}
}
}
|