Possible Duplicate:
Why can't I have protected interface members?
as title, in C#. Is there no possibility that someone might want to have a protected or an internal interface?
Interfaces are Coding contracts, this is the very reason it won't allow any access modifier other then Public in it's Method signatures. But an Interface by itself can be Internal but not private or protected, Internal allows access within the assembly which is perfectly fine.
Note: Nested interfaces and classes can have all access modifiers. Note: We cannot declare class/interface with private or protected access modifiers.
internal is the default if no access modifier is specified. Struct members, including nested classes and structs, can be declared public , internal , or private . Class members, including nested classes and structs, can be public , protected internal , protected , internal , private protected , or private .
Access modifiers define the access privileges of classes, interfaces, constructors, methods, and data members. Access modifiers consist of public, private , and protected . If no modifier is present, the default access of package-private is used. Table 8-2 provides details on visibility when access modifiers are used.
Because Interface is in crude terms 'a view to the outside world' and since it is for the outside world, there is no point making its members protected or private.
Or in other words, it is a contract with the outside world which specifies that class implementing this interface does a certain set of things. So, hiding some part of it doesn't make sense.
However, interfaces themselves can have access specifiers like protected
or internal
etc. Thus limiting 'the outside world' to a subset of 'the whole outside world'.
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