【转载】#438 - Benefits of Using Interfaces
You might wonder why you'd define an interface, have a class implement that interface and then access the class through the interface instead of just using the class directly.
One benefit of interface is that it allows you to treat different types of objects in the same way, provided that they implement a common interface.
For example, assume that we have Dog, Seal and DrillSergeant classes, all of which implement the IBark interface (which contains a Bark method). We can now store a collection of instances of these classes and ask all objects in our collection to Bark by using the IBark interface.
Dog kirby = new Dog("Kirby", );
Seal sparky = new Seal("Sparky");
DrillSergeant sarge = new DrillSergeant("Sgt. Hartman", "Tough as nails");
List<IBark> critters = new List<IBark>(){kirby, sparky, sarge};
// Tell everyone to bark
foreach (IBark barkingCritter in critters)
{
barkingCritter.Bark();
}


原文地址:#438 - Benefits of Using Interfaces
【转载】#438 - Benefits of Using Interfaces的更多相关文章
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- Architecture.SOLID-Principles
SOLID Principles Reference 1. Single Responsibility http://en.wikipedia.org/wiki/Single_responsibili ...
- 你应当如何学习C++(以及编程)(转载)
你应当如何学习C++(以及编程)(rev#1) By 刘未鹏(pongba) C++的罗浮宫(http://blog.csdn.net/pongba) Javascript是世界上最受误解的语言,其实 ...
- GJM :异步Socket [转载]
原帖地址:http://blog.csdn.net/awinye/article/details/537264 原文作者:Awinye 目录(?)[-] 转载请原作者联系 Overview of So ...
- RS-232, RS-422, RS-485 Serial Communication General Concepts(转载)
前面转载的几篇文章重点介绍了UART及RS-232.在工控领域除了RS-232以外,常用的串行通信还有RS-485.本文转载的文章重点介绍了RS-232.RS-422和RS-485. Overview ...
- RS-232 vs. TTL Serial Communication(转载)
RS-232串口一度像现在的USB接口一样,是PC的标准接口,用来连接打印机.Modem和其他一些外设.后来逐渐被USB接口所取代,现在PC上已经看不到它的身影了.开发调试时如果用到串口,一般都是用U ...
- 【转载】PHP使用1个crontab管理多个crontab任务
转载来自: http://www.cnblogs.com/showker/archive/2013/09/01/3294279.html http://www.binarytides.com/php- ...
- [转载] Android.Hook框架xposed开发篇
本文转载自: http://www.52pojie.cn/thread-396793-1-1.html 原帖:http://drops.wooyun.org/tips/7488 作者:瘦蛟舞 官方教程 ...
- [转载] google mock cookbook
原文: https://code.google.com/p/googlemock/wiki/CookBook Creating Mock Classes Mocking Private or Prot ...
随机推荐
- vue指令与事件修饰符
一.条件渲染指令 vue中提供了两个指令可以用于判断是否要显示元素,分别是v-if和v-show. 实例: <!DOCTYPE html> <html lang="en&q ...
- 8086键盘输入实验——《x86汇编语言:从实模式到保护模式》读书笔记07
1.BIOS中断 我们可以为所有中断类型自定义中断处理过程,包括内部中断.硬件中断和软中断. BIOS中断,又称BIOS功能调用,主要是为了方便地使用最基本的硬件访问功能.通常,为了区分针对同一硬件的 ...
- 随机森林(Random Forests)
简单地看了一些入门的资料. 随机森林似乎和CART有些联系. 随机森林的算法步骤: 1. 利用自助法(Bootstrap)从原始训练集中生成k个自助样本集,每个自助样本集是每棵分类树的全部训练数据.自 ...
- matlab矩阵中如何去掉重复的行;如何找到相同的行,并找到其位置
找到了2个函数:unique和ismember 1. 去掉其中的重复行:unique 例子: IDX = [,,; ,,; ,,; ,,; ,,; ,,]; classNo = unique(IDX, ...
- 代码重构----使用java有限状态机来消除太多的if else判断
1. 状态机基本概念 http://zh.wikipedia.org/wiki/%E6%9C%89%E9%99%90%E7%8A%B6%E6%80%81%E6%9C%BA 状态存储关于过去的信息,就是 ...
- vim脚本语言
转自:http://man.chinaunix.net/newsoft/vi/doc/usr_41.html#usr_41.txt Vim 脚本语言在很多地方用到,包括 vimrc 文件, 语法文件, ...
- NBUT 1107——盒子游戏——————【博弈类】
盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 110 ...
- 从零开始写C# MVC框架之--- 配置log4日志
在框架中配置日志分2步,一个是在帮助项目Zy.Utilities--Zy.Utility.Core中新建log类,封装写入日志方法,还需要在Zy.Utility.Core添加 log4net 的引用 ...
- mysql应用学习-windows(64位)安装和配置mysql(5.6.20)
下载安装包MySQL Installer 下载地址1:http://dev.mysql.com/downloads/windows/installer/ 说明:官网当前版本 5.6.22:虽然只有32 ...
- JavaScript各类型变量和对象
一.javascript支持的数据类型: var x=1 数字 var x=0.1 小数 var x=true/false bool var x="abc" 字符串 ...