也許要儘量減少對你的派生類重複的代碼。基本上不可能有一個不同的簽名的覆蓋,但肯定你可以重構你的代碼,你可以在基類中保留可能的重複代碼並在你的派生類中使用它。
public absctract class ImportBase()
{
//Making this protected here
protected virtual void CreateDocument()
{
//Your CreateDocument code
};
}
public class UsingOne : ImportBase
{
private override void CreateDocument()
{
// Override this if you have different CreateDocument for your different
// for different derived class.
}
public bool CreateDocument(string name)
{
// Do whatever you need to do with name parameter.
base.CreateDocument();
// Do whatever you need to do with name parameter.
return true; // return false;
}
}
您可以創建UsingOne
實例並調用CreateDocument(string name)
這是很有用的謝謝你,我嘗試它。 –
覆蓋將不得不被保護而不是私人。 –