Timeline for Is it permissible to use explicit interface implementation to hide members in C#?
Current License: CC BY-SA 3.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 23, 2017 at 12:40 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Oct 28, 2014 at 19:50 | comment | added | Esben Skov Pedersen | Sorry for the confusion. It should be ok now. | |
Oct 28, 2014 at 19:50 | history | edited | Esben Skov Pedersen | CC BY-SA 3.0 |
corrected confusion of ReadOnlyList vs (I)ReadOnlyCollection
|
Oct 28, 2014 at 19:35 | history | edited | Esben Skov Pedersen | CC BY-SA 3.0 |
deleted 17 characters in body
|
Oct 28, 2014 at 15:25 | comment | added | Jørgen Fogh | You write about IReadonlyCollection<T> but link to ReadOnlyCollection<T>. The first in an interface, the second is a class. IReadonlyCollection<T> does not implement IList<T> even though ReadonlyCollection<T> does. | |
Oct 28, 2014 at 14:33 | comment | added | Esben Skov Pedersen | @JørgenFogh see my edit | |
Oct 28, 2014 at 14:33 | history | edited | Esben Skov Pedersen | CC BY-SA 3.0 |
added 339 characters in body
|
Oct 28, 2014 at 10:38 | comment | added | Jørgen Fogh | Why would you assume that the methods would even be implemented at all? If a class implements IReadOnlyList it doesn't have to implement IList too. This has nothing to do with explicit interface implementation, which hides methods that must be present. | |
Oct 28, 2014 at 7:12 | comment | added | Esben Skov Pedersen | Well from a consumer point of view the methods are hidden. | |
Oct 28, 2014 at 0:10 | comment | added | Brian |
Of course, implementing Add explicitly also reduces clutter. TryAdd can do anything Add can do (Add is implemented as a call to TryAdd , so providing both would be redundant). However, TryAdd necessarily has a different name/signature, so it is not possible to implement IDictionary without this redundancy. Explicit implementation resolves this problem cleanly.
|
|
Oct 28, 2014 at 0:01 | comment | added | Brian |
I wouldn't say it hides the mutating setter but rather that it doesn't provide it at all. A better example would be ConcurrentDictionary , which implements various members of IDictionary<T> explicitly so that consumers of ConcurrentDictionary A) won't call them directly and B) can use methods which require an implementation of IDictionary<T> if absolutely necessary. E.g., users of ConcurrentDictionary<T> should call TryAdd rather than Add to avoid needing unnecessary exceptions.
|
|
Oct 27, 2014 at 23:55 | history | edited | Brian | CC BY-SA 3.0 |
Fixed link typo
|
Oct 27, 2014 at 21:04 | comment | added | Kyle Baran | Well it's my own interface I'll be using as well, so there's no sense in doing it wrong from the start. | |
Oct 27, 2014 at 21:00 | history | answered | Esben Skov Pedersen | CC BY-SA 3.0 |