0
이전 기본 방법자동으로 전화 나 기본 클래스가 파생 한
abstract class ClassPlugin
{
public ClassPlugin(eGuiType _guyType)
{
GuiType = _guyType;
}
public eGuiType GuiType;
protected void Notify(bool b)
{
...
}
protected virtual void RaiseAction()
{
Notify(false);
}
}
을하고 좀 파생 클래스가 : 내가 전에 호출 할 필요가 인상 조치에 지금
class ClassStartWF : ClassPlugin
{
public ClassStartWF(eGuiType _guyType) : base(_guyType) { }
public event delegate_NoPar OnStartWorkFlow_Ok;
public void Action()
{
Notify(true);
RaiseAction(eEventType.OK);
}
public new void RaiseAction(eEventType eventType)
{
base.RaiseAction();<--------------------
if (OnStartWorkFlow_Ok == null)
MessageBox.Show("Event OnStartWorkFlow_Ok null");
else
OnStartWorkFlow_Ok();
}
}
}
을 Base.RaiseAction() 메서드는 있지만 잊어 버릴 수 있습니다. 파생 된 메서드가 호출되기 전에 기본 메서드를 자동으로 호출하고 거기에서 일부 작업을 수행하는 방법이 있습니까?
public abstract class Base
{
// Note: this is *not* virtual.
public void SomeMethod()
{
// Do some work here
SomeMethodImpl();
// Do some work here
}
protected abstract void SomeMethodImpl();
}
그런 다음 파생 된 클래스는 단지
SomeMethodImpl
를 오버라이드 (override) :
왜 대신 * 최우선의'new'를 사용 * 'RaiseAction'? 이상한 접근법입니다. –
죄송합니다. – Luca
@Jon Skeet : 면밀한 조사에서 묻는 사람은 아무것도 무시하지 않는 것 같습니다. 기본 메소드에는 매개 변수가없고 파생 된 메소드가 있습니다. 코드가 전혀 이상하지 않습니다. – BoltClock