If I have a class with a method I want protected
and internal
. I want that only derived classes in the assembly would be able to call it.
Since protected internal
means protected
or internal
, you have to make a choice. What do you choose in this case - protected
or internal
?
Personally I would choose protected. If subclasses in your own assembly are good enough to call the method, why wouldn't a subclass in another assembly? Perhaps you could refactor the functionality into a separate (internal) class altogether.
You really need to think objectively about the purpose of the method. Internal accessibility almost always feels wrong to me. Mostly because of my experience trying to derive from controls or classes in the .NET framework where I ran into a brick wall because someone decided to mark a class or method as internal. The original author never noticed that not having access to that method made things much harder to implement a subclass.
EDIT
To clarify, internal accessibility for a class is very useful and I wasn't implying internal in general is bad. My point was that internal methods on an otherwise public class seems wrong to me. A properly designed base class should not give an unfair advantage to derived classes in the same assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With