我有一个抽象类和两个派生自这个主体类的类:
abstract class MainClass
{
public void DoSomething() {
if(isEdit())
Edit();
else if(isNew())
New();
else if(isDelete())
Delete();
else if(isSearch())
Search();
else if(isExit())
Exit();
}
public abstract void Edit();
public abstract void New();
public abstract void Delete();
public abstract void Search();
public abstract void Exit();
}
abstract class FirstClass : MainClass
{
public abstract void Edit();
public abstract void New();
public abstract void Delete();
}
abstract class SecondClass : MainClass
{
public abstract void Search();
public abstract void Exit();
}
当您需要从 FirstClass 扩展Edit()
,New()
并且Delete()
必须声明时,方法Search()
和Exit()
可以声明但不应该是强制性的。有没有办法做到这一点?