基础才是重中之重~再说面向接口的编程
生活随笔
收集整理的這篇文章主要介紹了
基础才是重中之重~再说面向接口的编程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
回到目錄
之前在我的文章中有對接口進行過講解,但感覺講的還是不夠清晰,不夠利針見血,這次我把面向接口的編程里,自認為比較核心的兩點說一下:
接口詳細介紹請看我的這篇文章
基礎才是重中之重~為什么C#有顯示實現接口
一切依賴于抽象,而不是實現
多個接口相同的行為,被一個對象實現
#region 多個接口相同的行為,被一個對象實現(一切依賴于抽象,而不是實現)interface IRepository{void Insert();}interface IRepositoryAsync{void Insert();}class Repository : IRepository{#region IRepository 成員public void Insert(){Console.WriteLine("同步添加");}#endregion}class RepositoryAsync : IRepository, IRepositoryAsync{#region ICowBoy 成員void IRepository.Insert(){Console.WriteLine("同步添加");}#endregion#region IRepositoryAsync 成員void IRepositoryAsync.Insert(){Console.WriteLine("異步添加");}#endregion}#endregion接口實現的多態性
一個接口,多種實現(多態)
#region 一個接口,多種實現(多態)interface IHello{void Morning();void Noon();void Night();}class Chinese : IHello{#region IHello 成員public void Morning(){Console.WriteLine("早上好");}public void Noon(){Console.WriteLine("中午好");}public void Night(){Console.WriteLine("晚上好");}#endregion}class English : IHello{#region IHello 成員public void Morning(){Console.WriteLine("Good Morning");}public void Noon(){Console.WriteLine("Good Noon");}public void Night(){Console.WriteLine("Good Night");}#endregion}#endregion對于我們開發人員來說,有時,對一個知識的真正理解是需要一個過程,一個時間的,所以建議初學者,應屆畢業生同學不用太著急,這個是需要一個過程的,呵呵!
回到目錄
總結
以上是生活随笔為你收集整理的基础才是重中之重~再说面向接口的编程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用 bugly 分析应用崩溃
- 下一篇: 程序员的责任