[問題] 程序 繼承 的好辦法?
各位大大好,個人想詢問繼承的問題,
假設我有個方法執行內容完全,只有在繼承的時候需要多了一些判斷
想詢問該怎麼撰寫會比較好?
下面是情境舉例,
想問有人有好解法嗎?
----- 舉例 -----
我有個父類別 BackgroundWorker Call_DoWork 執行如下
bool stop = false;
protected void Call_DoWork(object sender, DoWorkEventArgs e)
{
var worker = sender as BackgroundWorker;
bool complete = false;
while(!worker.CancellationPending & !stop & !complete)
{
Step1();
if(!worker.CancellationPending & !stop)
Step2();
if(!worker.CancellationPending & !stop)
Step3();
if(!worker.CancellationPending & !stop)
{
Step4();
complete = true;
}
}
}
我有個子類別繼承父類別並override Call_DoWork 如下
override protected void Call_DoWork(object sender, DoWorkEventArgs e)
{
var worker = sender as BackgroundWorker;
bool complete = false;
while(!worker.CancellationPending & !stop & !complete & rs232.IsOpen)
{
Step1();
if(!worker.CancellationPending & !stop & rs232.IsOpen)
Step2();
if(!worker.CancellationPending & !stop & rs232.IsOpen)
Step3();
if(!worker.CancellationPending & !stop & rs232.IsOpen)
{
Step4();
complete = true;
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.235.221
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1552121029.A.214.html
※ 編輯: s4300026 (60.250.235.221), 03/09/2019 16:52:13
※ 編輯: s4300026 (60.250.235.221), 03/09/2019 17:10:56
推
03/09 17:45,
6年前
, 1F
03/09 17:45, 1F
→
03/09 17:45,
6年前
, 2F
03/09 17:45, 2F
→
03/09 17:46,
6年前
, 3F
03/09 17:46, 3F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章