In an interview a while ago for a .NET position the interviewer asked me ‘what would you use a private interface for?’.
I asked him did he mean the difference between implicit vs explicit interface implementation to which he answered no.
So I’m wondering:
- What he meant?
- What you would use a private interface for?
An interface could be private within another class
in terms of utility it simply hides from other code, even within the same assembly, that said interface exists. The utility of this is not terribly high in my opinion.
Explicit interface implementation is a different matter, has some very useful cases (especially when working with generics and older non generic interfaces) but I would not term it ‘private interfaces’ and would not say that the term is commonly used in that manner.
Using the two techniques together you can do:
This allows you to expose the nested classes in some fashion while allowing the parent class to invoke methods on them that the outside world cannot. This is a potentially useful case but is not something I would wish to use very often. Certainly it’s use in an interview smacks of being a boundary case the interviewer is using because they’ve seen it and though it was ‘interesting’