下面的代碼好嗎?我在問自己界面中的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();}
使用沒有抽象的 Base 方法
慕尼黑8549860
2021-08-22 18:00:58