Is it reasonable to have method in sealed class with greater accessability than the class itself.
Of course just not taking into consideration later refactoring…
Example
class SomeClass
{
public void SomeMethod()
{
...
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(My answer is for C# only)
Of course it can be useful!
Reason 1:
The access modifiers cannot all be put in order.
Would you say that
protectedwas more accessable thaninternal, or less?Reason 2:
Overriding bace class methods and implementing interfaces:
Now by casting a MyClass to Object, the method can be exposed outside the assembily.
This pattern is often used when implementing IEnumerator. Often the real class will be private (not even internal).
Reason 3:
Access to a private nested class: