![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Originally published at Fiberglass flowers. You can comment here or there.
It was pretty strange for me to get a “CS0103: The name ‘AppliesToNode’ does not exist in the current context” from C# compiler for a code:
class Copyrighted : IBackend { bool IBackend.AppliesToNode(string Uri) { return something; } ... if (!this.AppliesToNode(Uri)) { ...}
while (this as IBackend).AppliesToNode(PexUri)
compiles.
- On one hand, it’s pretty strange:
Copyrighted
IS aIBackend
, why not accessig its public members? It breaks Liskov substitution principle in certain sense; - On other hand, separation of namespaces is good: it decreases coupling.
Later I found a following paraagraph in ECMA-334, item 20.4.1:
Explicit interface member implementations have different accessibility characteristics than other members. Because explicit interface member implementations are never accessible through a qualified interface member name in a method invocation or a property access, they are in a sense private. However, since they can be accessed through an interface instance, they are in a sense also public.
And even:
Because explicit interface member implementations are not accessible through class or struct instances, they allow interface implementations to be excluded from the public interface of a class or struct.
So this is even a primary aim of the explicit interface implementation: to EXCLUDE interface members from class signature. You will not be able to call these members on class-typed variable: only cast it to interface.
I take it as “static const” rule in C++: no good way to decide which way is better, so just take one of them.