Hey all
Here is my question Consider two classes
Class A : SomeSystemClassA
Class B : SomeSystemClassB
Now I have to add a common interface to both class A and class B. The
way A and B are derived I cannot add a common abstract base class for
them.
So I do
Class A : SomeSystemClassA, ICommonInterface
Class B : SomeSystemClassB, ICommonInterface
The problem I am facing is that C# doesn't allow interfaces to have
static functions or for that matter any function implementation (unless
I am missing something )
In a scenario like this if ICommonInterface had 10 funcs chances are A
and B contain 3 functions that are exactly the same resulting in code
duplication in A and B
How can this problem be solved? Is there a way better than this method?
Have a CommonInterfaceImplClass property on ICommonInterface and in
class A and B have all methods dispatch the call to
CommonInterfaceImplClass.
Class A
{
Void CommonFunc1()
{
CommonInterfaceImplClass. CommonFunc1()
}
}
Class B
{
Void CommonFunc1()
{
CommonInterfaceImplClass. CommonFunc1()
}
}
Still code duplication but not a maintenance nightmare.