Last post Nov 26, 2013 07:17 AM by PatriceSc
Nov 26, 2013 05:18 AM|TheNutCracker|LINK
Can somebody explain to me if the "ICollection" interface has already declared the requirement to implement the "IEnumerable" interface, why would it be necessary to be declared a second time in the concrete object defintion?
// Defines the set of information that constitutes input to security policy
// decisions. This class cannot be inherited.
public sealed class Evidence : ICollection, IEnumerable
There is already an obligation(or understanding, not sure how to word it, a contract maybe?) to implement IEnumerable in the ICollection interface. Is it necessary to state this a second time?
Nov 26, 2013 05:42 AM|PatriceSc|LINK
What happens if you don't ? It should work.
Nov 26, 2013 05:44 AM|TheNutCracker|LINK
That's what I thought too. This is "official" Microsoft code. You can check the code yourself. I included the namespace. :)
System.AppDomain.CurrentDomain.Evidence is the property that lead me back to the code I posted above.
Edit #1: My thoughts. The only thing I can come up with right now to answer my own question is, maybe it's a simply a visual reminder to refresh ones memory as to what interfaces need to be implemented in the class. Maybe that was the intent. Other than
that, probably just superfluous code that could be removed.
Nov 26, 2013 07:17 AM|PatriceSc|LINK
If seen in "View definition", you'll likely always see all implemented interfaces regardless of the actual source code (this tool likely just inspects the metadata and list all implemented interfaces regardless of their relationship and without trying to
simplify the code).
As far as the compiler is concerned, the general "do the simplest thing that works" likely applies here. You would get no real benefit from forbidding to tell that a class implements an interface when this is already the case because of another interface.
It just doesn't worth the extra work and it allows to make things more explicit if you want.
Similarly for IEnumerable we discussed earlier, the goal is likely to just have the simplest interface one could use and add additional features such as Count in other interfaces etc...
I remember also the language designer said the same thing about some "missing" features (such as "checked exceptions"). Basically it's better to just do the simplest thing that works and enhance later as needed rather than doing something more complex and
realize it was a wrong design decision and having to live with this...