【转载】#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 ...
随机推荐
- java se系列(四) 函数、数组、排序算法、二分法、二维数组
1 函数 1.1 数的概述 发现不断进行加法运算,为了提高代码的复用性,就把该功能独立封装成一段独立的小程序,当下次需要执行加法运算的时候,就可以直接调用这个段小程序即可,那么这种封装形形式的具体表 ...
- matplotlib中绘图配色
Python中绘图配色(参照博文: Python-画图(散点图scatter.保存savefig)及颜色大全) # 可以直接使用配色编码 c=["#A52A2A" if tag = ...
- jumpserver 安装详解
一,下载软件 下载前安装依赖软件 yum install -y epel-release yum -y install git python-pip my ...
- org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.
今天报了这个异常,这是页面报的 org.springframework.dao.DataIntegrityViolationException: could not execute statement ...
- xss攻击汇总--转
(1)普通的XSS JavaScript注入<SCRIPT SRC=http://3w.org/XSS/xss.js></SCRIPT>(2)IMG标签XSS使用JavaScr ...
- 【Elasticsearch】集群管理
8.1 Elasticsearch时光机 Elasticsearch的快照,防止出错,灾备8.1.1 创建快照存储库创建快照之前必须建一个存储库,有如下几个方面,name,type,settings, ...
- [转]ASP.NET MVC中的两个Action之间值的传递--TempData
本文转自:ASP.NET MVC中的两个Action之间值的传递--TempData 一. ASP.NET MVC中的TempData 在ASP.NET MVC框架的ControllerBase中存在 ...
- js 获取 Url.Action 设置area
var url = '@Url.Action("UserEdit","User",new { Area = "Setup", id = 1} ...
- C# string Stream 互转
使用C#将字符串转化成流,将流转换成字符串,代码如下: using System.IO; using System.Text; namespace CSharpConvertString2Stream ...
- lua load
load (chunk [, chunkname [, mode [, env]]]) 加载一个代码块. 如果 chunk 是一个字符串,代码块指这个字符串. 如果 chunk 是一个函数, load ...