第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用沒有抽象的 Base 方法

使用沒有抽象的 Base 方法

C#
慕尼黑8549860 2021-08-22 18:00:58
下面的代碼好嗎?我在問自己界面中的Start()andStop()方法ICustomTimer是否可以作為位置。因?yàn)槲以?Main 方法中需要它。這是一種代碼異味,或者換句話說,調(diào)用沒有抽象的基本方法的最佳實(shí)踐是什么?Timer類沒有可用于繼承的接口。public interface ICustomTimer{    string Value { get; set; }    //Implementation in Timer    void Start();    //Implementation in Timer    void Stop();}public class CustomTimer : System.Timers.Timer, ICustomTimer{    public string Value { get; set; }}public Main(){    var customTimerObj = iocContainer.Get<ICustomTimer>();    customTimerObj.Start();}
查看完整描述

1 回答

?
縹緲止盈

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊

這是一個(gè)有效的用途,甚至是一個(gè)很好的用途,如果您只想在使用接口時(shí)調(diào)用類方法,否則您可以這樣做:


public interface ICustomTimer

{

    string Value { get; set; }


    //Implementation in Timer

    void Start();


    //Implementation in Timer

    void Stop();

}


public class CustomTimer : System.Timers.Timer, ICustomTimer

{

    public string Value { get; set; }

    void ICustomTimer.Start() { this.Start(); }

    void ICustomTimer.Stop() { this.Stop(); }

}

這樣你就可以做其他事情(在 Timer 類之前或發(fā)布方法調(diào)用)


查看完整回答
反對 回復(fù) 2021-08-22
  • 1 回答
  • 0 關(guān)注
  • 174 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號