Base Class Method reuse with different client.

  • Thread starter Thread starter Joshft
  • Start date Start date
J

Joshft

Guest
I have a base class and 3 client inherit from base and all of them will use a same method with tiny logic change.

Should I implement this method in 3 client class or Can I use if else in base class?


public class BaseClass
{
protected string className;
public BaseClass()
{
className = "Base";

}
private void ReuseMethod()
{
commonLogic1();
if (className.Equal("A") commonLogic2();
commonLogic3();
if (className.Equal("B") commonLogic4();
commonLogic5();
if (className.Equal("C") commonLogic6();
}
}
public class ClassA : BaseClass
{
public ClassA() : Base()
{
className = "A";
}
}
public class ClassB : BaseClass
{
public ClassB () : Base()
{
className = "B";
}
}
public class ClassC : BaseClass
{
public ClassC () : Base()
{
className = "C";
}
}

Continue reading...
 
Back
Top