Click here to Skip to main content
15,889,992 members
Home / Discussions / C#
   

C#

 
GeneralRe: Implementing Interfaces Pin
Richard Andrew x6416-Nov-11 16:49
professionalRichard Andrew x6416-Nov-11 16:49 
GeneralRe: Implementing Interfaces Pin
Not Active16-Nov-11 16:51
mentorNot Active16-Nov-11 16:51 
GeneralRe: Implementing Interfaces Pin
Richard Andrew x6416-Nov-11 16:53
professionalRichard Andrew x6416-Nov-11 16:53 
AnswerRe: Implementing Interfaces Pin
Wayne Gaylard16-Nov-11 17:07
professionalWayne Gaylard16-Nov-11 17:07 
GeneralRe: Implementing Interfaces Pin
Richard Andrew x6416-Nov-11 17:10
professionalRichard Andrew x6416-Nov-11 17:10 
GeneralRe: Implementing Interfaces Pin
Wayne Gaylard16-Nov-11 17:17
professionalWayne Gaylard16-Nov-11 17:17 
AnswerRe: Implementing Interfaces Pin
BillWoodruff16-Nov-11 19:28
professionalBillWoodruff16-Nov-11 19:28 
AnswerRe: Implementing Interfaces Pin
BobJanova16-Nov-11 23:25
BobJanova16-Nov-11 23:25 
In general I'd only ever do this if there is a name clash with a method from another interface or which already exists in the class hierarchy. The commonest case is implementing IEnumerable<T>, when you need to provide two GetEnumerator methods.

However, the linked article from the answer above mine raises an interesting point: if the interface is only implemented for infrastructure reasons and you never expect an 'end user' developer to actually call the methods on your class manually, it might make sense to explicitly implement them. So one might argue that both GetEnumerators should be explicitly implemented, as they're there for infrastructure reasons (being able to enumerate over the class) and not to be called directly.

For a custom interface that would be true if it is something which has special meaning for a framework you have created, so all a class needs to do from an external point of view is implement it and some clever stuff happens. For example let's imagine a slightly cleverer version of my socket library which specified an interface thus:

public interface ITransferrable {
 /// <summary> Gets the bytes to transfer when this object is
 /// sent over a socket. </summary>
 byte[] GetBytes();

 /// <summary> Restores the internal state of this object from transferred bytes.</summary>
 void Restore(byte[] bytes);
}


... and some magic which I won't go into (restoring would be slightly non-trivial and writing that out wouldn't help the point) which allowed you to send and retrieve ITransferrables through the normal send/receive mechanism.

Apart from code inside Sockets.cs, no-one would ever explicitly call those two methods. So, even without a name clash, it might well make sense to explicitly implement that interface, because you don't need to see them when you are inspecting the implementing class in a domain context.
QuestionHow do you handle this? Pin
Rojan Gh.16-Nov-11 14:57
professionalRojan Gh.16-Nov-11 14:57 
QuestionInterop: Anyone know how to save an Excel workbook without the "Do you want to save" popup? Pin
Alaric_16-Nov-11 4:01
professionalAlaric_16-Nov-11 4:01 
AnswerRe: Interop: Anyone know how to save an Excel workbook without the "Do you want to save" popup? Pin
Not Active16-Nov-11 4:07
mentorNot Active16-Nov-11 4:07 
GeneralRe: Interop: Anyone know how to save an Excel workbook without the "Do you want to save" popup? Pin
Alaric_16-Nov-11 4:09
professionalAlaric_16-Nov-11 4:09 
AnswerRe: Interop: Anyone know how to save an Excel workbook without the "Do you want to save" popup? Pin
Alaric_16-Nov-11 4:08
professionalAlaric_16-Nov-11 4:08 
QuestionZoom window box (attached to mouse pointer) Pin
Blubbo16-Nov-11 3:39
Blubbo16-Nov-11 3:39 
QuestionWinForms - Detect End of RichTextBox Pin
Matt U.16-Nov-11 2:40
Matt U.16-Nov-11 2:40 
AnswerRe: WinForms - Detect End of RichTextBox Pin
V.16-Nov-11 3:56
professionalV.16-Nov-11 3:56 
GeneralRe: WinForms - Detect End of RichTextBox Pin
Matt U.16-Nov-11 4:48
Matt U.16-Nov-11 4:48 
GeneralRe: WinForms - Detect End of RichTextBox Pin
V.25-Nov-11 3:23
professionalV.25-Nov-11 3:23 
AnswerRe: WinForms - Detect End of RichTextBox Pin
BobJanova16-Nov-11 6:07
BobJanova16-Nov-11 6:07 
GeneralRe: WinForms - Detect End of RichTextBox Pin
Matt U.16-Nov-11 8:20
Matt U.16-Nov-11 8:20 
GeneralRe: WinForms - Detect End of RichTextBox Pin
Pete O'Hanlon16-Nov-11 8:45
mvePete O'Hanlon16-Nov-11 8:45 
GeneralRe: WinForms - Detect End of RichTextBox Pin
Matt U.16-Nov-11 8:50
Matt U.16-Nov-11 8:50 
GeneralRe: WinForms - Detect End of RichTextBox Pin
BobJanova16-Nov-11 23:16
BobJanova16-Nov-11 23:16 
AnswerRe: WinForms - Detect End of RichTextBox Pin
BillWoodruff16-Nov-11 14:41
professionalBillWoodruff16-Nov-11 14:41 
QuestionBug in ShowWindow in Windows 7 Pin
Axonn Echysttas16-Nov-11 2:08
Axonn Echysttas16-Nov-11 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.