Consider the following scenario:
public interface ITestInterface
{
void TestMethod1();
void TestMethod2();
}
public class TestParent
{
void SomeMethod()
{
Console.Writeln("Method of test parent");
}
}
public class Test1: TestParent, ITestInterface
{
void TestMethod1()
{
Console.WriteLine("Implementation 1 of TestMethod1");
}
void TestMethod2()
{
Console.log("Same implementation");
}
}
public class Test2: TestParent, ITestInterface
{
void TestMethod1()
{
Console.WriteLine("Implementation 2 of TestMethod1");
}
void TestMethod2()
{
Console.log("Same implementation");
}
}
TestParent is an existing class and Test1 and Test2 are the child classes of TestParent and implement ITestInterface.
In my above example, both the class have the same implementation for TestMethod2(). I was just wondering how to avoid duplicate code? I am planning to add couple more classes and they all have the same implementation for TestMethod2.