Ok, this is a question I'm asking, not as in demonstrating good coding practices (this actually could be considered a bad practice) but rather in regards to 'can' it be done at all.
That said, in VB.NET you implement an interface like this...
Sub SomeInterfaceMember()
Implements ISomeInterface.SomeInterfaceMember
End Sub
while in C# you do it explicitly like this (which can only be called via the interface)...
void ISomeInterface.SomeInterfaceMember(){}
or more simply, implicitly like this (in which case you can call it directly, or via the interface)...
void SomeInterfaceMember(){} // <-- This name matches the interface member
However, regarding VB, you can also do this, using any name you want for the member...
Sub SomeRandomMemberName() // <-- This name doesn't match the interface member
Implements ISomeInterface.SomeInterfaceMember
End Sub
In other words, the method that handles the implementation can have a completely different name than the interface's member name.
I'm just wondering if there's something similar to this in C#. (Yes, I know I can simply do an explicit interface, then access it via another 'wrapper' member with a different name that simply delegates to it, but in VB.NET, you do both with a single method.)
So can that be done?
Mark
IDisposable
and you wish to have aClose
method, you can roll them into one withSub Close Implements IDisposable.Dispose
. Brief, readable. – WaspIWoozle.Foo()
implemented by a public methodWoozleClass.Bar()
seems like a code smell. I would see nothing wrong, however, with having anIWoozle.Foo() implemented by a *protected* method
IWoozleFoo()` if the nameFoo
was otherwise taken. To my mind, having a public methodClose
implementIDisposable.Dispose()
makes a promise that the two functions will always behave absolutely identically; in practice one may often want to allow for divergent semantics (e.g. allow a re-open following a Close but not Dispose, etc.). – KlattDispose
/Close
ones, which I don't like as advice. – Klatt