Is this an acceptable design ??
Abstract class
public abstract class SomethingBase
{
public abstract int Method1(int number1);
public abstract int Method2(int number2);
}
public class Class1 : SomethingBase
{
public override int Method1(int number1)
{
//implementation
}
//i dont want this method in this class
public override int Method2(int number2)
{
throw new NotImplementedException();
}
}
public class Class2 : SomethingBase
{
//i dont want this method in this class
public override int Method1(int number1)
{
throw new NotImplementedException();
}
public override int Method2(int number2)
{
//implementation
}
}
I mean the situation if I need method1 in my Class1 and the method2 not and vica verse for Class2. In fact the methods are excluding each other in the derived classes.
It is not an acceptable design as it stands. To make it much more acceptable, you could implement two interfaces on the abstract class. One for Method1()
and one for Method2()
, and simply use the interface object to pass that around.
You really don't want to use the Class1
and Class2
definitions, as there is a danger of your clients calling the method that is not implemented. So I'd suggest to use interfaces and use these instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With