【转载】#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 ...
随机推荐
- archlinux安装交叉编译工具链
1. 在/usr/local下新建文件夹:arm [guo@archlinux local]$sudo mkdir arm 2. 将交叉编译工具拷贝到arm文件夹中 [guo@archlinux ...
- ubuntu root用图形界面登录
http://blog.csdn.net/weimine/article/details/69055536 http://blog.csdn.net/gongxifacai_believe/artic ...
- CI 框架中的日志处理 以及 404异常处理
最近在整理项目中的日志问题,查了一些关于 “CI 框架中的日志处理 以及 404异常处理” 的东西,顺便记录一下: 关于错误日志: 1. 在CI框架中的 system/core/CodeIgniter ...
- ansible 命令详解{图片详解}
本文内容来至于http://www.zsythink.net 文件操作模块 命令操作模块 cron 包管理模块
- params传递任意参数
namespace 传递任意参数{ class Program { static void Main(string[] args) { //可传递任意数量参数 Test(1, 2, "sas ...
- php之mongodb插入数据后如何返回当前插入记录ID
<?php /** *插入记录 *参数: *$table_name:表名 *$record:记录 * *返回值: *成功:true *失败:false */ function insert($t ...
- tomcat一个IP绑定多个域名,不同域名访问不同的应用
修改conf文件夹下面的server.xml的Engine里面的内容即可原始内容如下: …… <Engine name="Catalina" defaultHost=&quo ...
- 2017年11月4日 vs类和结构的区别&哈希表&队列集合&栈集合&函数
类和结构的区别 类: 类是引用类型在堆上分配,类的实例进行赋值只是复制了引用,都指向同一段实际对象分配的内存 类有构造和析构函数 类可以继承和被继承 结构: 结构是值类型在栈上分配(虽然栈的访问速度比 ...
- 【学习笔记】实用类String的基本应用即常用方法
一.String类概述 在Java中,字符串被作为String类型的对象来处理. String类位于java.lang包中,默认情况下会自动导入到所有的程序中. 创建String对象的方法如下: St ...
- guava的限流工具RateLimiter使用
guava限流工具使用 非常详细的一篇使用博客:https://www.cnblogs.com/yeyinfu/p/7316972.html 1,原理:Guava RateLimiter基于令牌桶算法 ...