笔记_接口隔离原则_显示实现接口

显示实现接口的意义:
在于一般情况下隐藏该接口的方法,在特别的情况下才予以显示,调用。
实际项目中的例子:暂无,后续补充。

namespace
Test { /*接口显示实现*/ public class Program { static void Main(string[] args) { IKiller killer = new WarmKiller(); killer.Kill(); var wk = killer as IGentleman; wk.Love(); Console.Read(); } } interface IGentleman { void Love(); } interface IKiller { void Kill(); } class WarmKiller : IGentleman, IKiller { public void Love() { Console.WriteLine("Farewell, my beloved girl! I just can't love you forever!"); } //这里显示实现IKiller接口,那么就只有IKiller类型才可以调用Kill方法 void IKiller.Kill() { Console.WriteLine("Sorry, the young idiot has been killed by himself, He's not the one he was."); } } }

猜你喜欢

转载自www.cnblogs.com/hansel520/p/12141801.html