【转载】#446 - Deciding Between an Abstract Class and an Interface
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
【转载】#446 - Deciding Between an Abstract Class and an Interface的更多相关文章
- php中的抽象类(abstract class)和接口(interface)
一. 抽象类abstract class 1 .抽象类是指在 class 前加了 abstract 关键字且存在抽象方法(在类方法 function 关键字前加了 abstract 关键字)的类. 2 ...
- 《Beginning Java 7》 - 7 - abstract class 抽象类 和 interface 接口
1. 抽象类: 为什么用抽象类: 一些 generic 的类本身并没有现实意义,所以不需要被实例化.比如动物,自然界没有动物这个物种,但却有无数的继承自动物的物种,那么动物本身可以是一个抽象类. 抽象 ...
- Receiver class com.mchange.v2.c3p0.impl.NewProxyResultSet does not define or inherit an implementation of the resolved method 'abstract boolean isClosed()' of interface java.sql.ResultSet.
背景: Mayabtis+springboot项目,连接数据库发生异常 报错内容: java.lang.AbstractMethodError: Receiver class com.mchange. ...
- 虚方法(virtual)和抽象方法(abstract)的和接口(interface)的区别
虚方法(virtual)和抽象方法(abstract)的区别 2017年06月15日 13:41:26 阅读数:65 注:本文转载自 http://www.cnblogs.com/michaelxu/ ...
- Abstract和Virtual和interface , 派生类中重写 override / new关键字
http://www.cnblogs.com/blsong/archive/2010/08/12/1798064.html C#中Abstract和Virtual 在C#的学习中,容易混淆virtua ...
- JAVA的abstract修饰符 && 接口interface用法 && 抽象类和interface的差别
abstract修饰符可以修饰类和方法. (1)abstract修饰类,会使这个类成为一个抽象类,这个类将不能生成对象实例,但可以做为对象变量声明的类型(见后面实例),也就是编译时类型.抽象类就相当于 ...
- 面向对象_06【抽象类:abstract、接口:interface、实现:implements】
抽象类:abstract抽象:没有足够的描述功能,事物不具体的描述,却又有共性. 特点: 1,方法只有声明没有实现时,该方法就是抽象方法,需要被abstract修饰,抽象方法必须定义在抽象类中,该类也 ...
- Java抽象类(Abstract Class)与接口(Interface)区别
抽象类与接口比较 抽象类跟接口类似,都不能实例化,可能包含不需实现方法或已实现的方法. 抽象类可以定义一些不是静态或常量的字段,定义 public, protected, private访问级别的具体 ...
- C#中的Abstract、Virtual、Interface理解
容易混淆是必须的,都是与继承有关系,并且涉及到override的使用 一.Virtual方法(虚方法) virtual 关键字用于在基类中修饰方法.virtual的使用会有两种情况: 情况1:在基类中 ...
随机推荐
- vue搭建后台管理页面(点击左侧导航,切换右侧内容)
home.vue页面 <template> <div style="background-color: #EBEBEB;min-height:900px"> ...
- 日志收集之filebeat
一,软件介绍 Filebeat是一个轻量级日志传输Agent,可以将指定日志转发到Logstash.Elasticsearch.Kafka.Redis等中.Filebeat占用资源少,而且安装配置也比 ...
- shell基础优化脚本
#!/bin/bash ######################################################### #Created Time: Tue Aug 7 01:29 ...
- OSG DB的插件地址设置
今天搞了一整天OSG,结果每次都说could not find plugin,就是说找不到OSG的插件去加载文件,我大概看了下OSG的插件机制,发现他是用插件的形式下去读取文件的 http://blo ...
- (转)DB2 db2diag.log 日志分析
DB2 db2diag.log 日志分析 原文:http://blog.csdn.net/lyjiau/article/details/52129997 db2diag.log是用来记录DB2数据库运 ...
- pat00-自测4. Have Fun with Numbers (20)
00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yu ...
- Springboot - 集成 JPA
1.什么是 JPA? JPA就是Java Persistence API的意思,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. 2. JPA 具有什么优 ...
- springboot整合mongo多数据源
该实例已测试 POM.XML <!-- Spring Boot mongodb 依赖--> <dependency> <groupId>org.springfram ...
- 【linux】netstat 详解
Linux netstat命令用于显示网络状态. 利用netstat指令可让你得知整个Linux系统的网络情况. 在Internet RFC标准中,Netstat的定义是: Netstat是在内核中访 ...
- solidity数据类型
1.Bool类型 取值:true/false 运算符:! && || == != 2.Integer整型 uint8-uint256 int8-int256 uint == uint ...