Hi all,
I'm having a little problem designing an
Interface
I have (not the GUI).
What I basically have is two
Interfaces
that do the same, but one of them needs to get an extra parameter to a
Function
.
Public Interface IDoSomething(Of T)
Function DoSomething(ByVal something As T) As String
End Interface
Public Interface IDoSomethingSlightlyDifferently(Of T)
Inherits IDoSomething(Of T)
Function DoSomething(ByVal s As String, ByVal something As T) As String
End Interface
The above is not impossible, but the
IDoSomethingSlightlyDifferently
now has an overload for the
DoSomething Function
. One that will never be called...
The
IDoSomething
is to be used and implemented by the user and another
Class
uses
IDoSomething
as an input parameter.
IDoSomethingSlightlyDifferently
is to be called from some
Reflection
code (which calls the overloaded function).
So while both
Interfaces
serve the same purpose the manner in which they are called is different. Does that mean one should not
Inherit
the other? Or should I Inherit them and simply have an empty
Function
that throws a
<code>
NotImplementedException?
Actually, as I wrote this I think I found my own answer.
IDoSomething
and
IDoSomethingSlightlyDifferent
are probably never interchangeable. You either
Implement
one and the other will never be called or you
Implement
both and you now have a
Class
that does two things (which look the same, but are still slightly different). So I guess the answer is they shouldn't
Inherit
.
I'm still curious and looking forward to some of your opinions on this matter. It's something that has been bugging me for a while.
Thanks.