An abstract class is a base class that may have some members not implemented in the base class, but only in the derived classes. An interface is just a contract that a class can choose to fulfill - a list fo member that it must implement if it implements the interface.

You'll often use an abstract class when you use nouns to describe the is-a relationship between a base class and derived classes. E.g. Person as an abstract class and Man and Woman as derived classes.

By contrast, you'll often use interfaces when you think about verbs that describe things that instances of a class can do. E.g. IRun interface containing Run method, implemented by Man and Woman, but also Horse classes.

 public abstract class Person
// ... public class Man: Person, IOperateTools, IDriveTractor
// ... public class Woman: Person, IAskForDirections, ICollaborate
// ...

原文地址:#446 - Deciding Between an Abstract Class and an Interface

最新文章

  1. C#环境
  2. SQLServer2014内存优化表评测
  3. 【jmeter】关联-正则表达和xpath
  4. 【解题报告】[动态规划] RQNOJ - PID273 / 马棚问题
  5. Linux操作系统
  6. Jsp的内置标签和jstl标签
  7. tomcat下部署activemq(转)
  8. Spring3表达式语言(SpEL)学习笔记
  9. 给Notepad++ 加右键菜单带图标
  10. CountDownLatch, CyclicBarrier and Semaphore
  11. 【Java入门提高篇】Day6 Java内部类——成员内部类
  12. ajax请求 readyState为0 可能原因之一
  13. (四十九)Quartz2D自定义控件
  14. zip压缩解压
  15. c# webapi 跳转
  16. HelloWorld 之JasperReports初步
  17. Table does not have the identity property. Cannot perform SET operation.
  18. Building a Space Station---poj2031(最小生成树)
  19. select2加载远程数据示例
  20. go语言基础之map赋值、遍历、删除 、做函数参数

热门文章

  1. PIE SDK地图范围设置
  2. 破解myBase试用到期
  3. os.popen('python hello_out.py')中Python程序执行时默认的当前路径为MS-DOS CMD的默认路径
  4. 【ORACLE】sqlplus使用记录
  5. Jascript面向对象
  6. solidity数据类型
  7. Android DataBinding实现地址三联动
  8. HihoCoder#1279 : Rikka with Sequence(dp 枚举子集 二进制 神仙题)
  9. js 的起源故事
  10. javascript统计一个字符在一段字符串出现次数