PHP的接口(interface)
接口声明了函数和字段,但不会给出实现的细节
规则:
1.类全部为抽象方法(不需要声明abstract)
2.接口抽象方法必须是public
3.成员(字段)必须是常量
interface Computer{
const Name="联想";
//默认是abstract(抽象的)方法
public function run();
}
class Notebook implements Computer {
public function run(){
echo '实现了接口的方法';
}
}
$ntbcom = new Notebook();
echo Computer::Name; //输出值:联想
$ntbcom->run(); //输出值:实现了接口的方法
继承对个接口
interface Computer{
const Name="联想";
//默认是abstract(抽象的)方法
public function run();
}
interface Notebook{
//默认是abstract
public function book();
}
class NotebookComputer implements Computer, Notebook{
public function run(){
echo '实现了接口的方法';
}
public function book(){
echo '实现了接口的方法!';
}
}
PHP的接口(interface)的更多相关文章
- java中的接口interface
关于接口 接口描述了实现了它的类拥有什么功能.因为Java是强类型的,所以有些操作必须用接口去约束和标记.接口作为类的能力的证明,它表明了实现了接口的类能做什么. 类似与class,interface ...
- php中的抽象类(abstract class)和接口(interface)
一. 抽象类abstract class 1 .抽象类是指在 class 前加了 abstract 关键字且存在抽象方法(在类方法 function 关键字前加了 abstract 关键字)的类. 2 ...
- 14 接口-interface的定义与实现
接口的基本语法一: 1.使用interface 定义 2.接口当中的方法都是抽象方法 3.接口当中的方法都是public权限 接口的定义: interface USB { public void re ...
- C#编程利器之三:接口(Interface)【转】
C#编程利器之三:接口(Interface) C#接口是一个让很多初学者容易迷糊的东西,用起来好象很简单,定义接口,然后在里面定义方法,通过继承与他的子类来完成具体的实现.但没有真正认识接口的作用的时 ...
- 为什么不能把委托(delegate)放在一个接口(interface)当中?
stackoverflow上有人问,为什么不能把委托放在一个接口当中? 投票最多的第一个答案第一句话说,“A Delegate is just another type, so you don't g ...
- java之接口interface
接口 1.多个无关的类可以实现同一个接口 2.一个类可以实现多个无关的接口 3.与继承关系类似,接口与实现类之间存在多态性 4.定义java类的语法格式 < modifier> class ...
- 【Java 基础篇】【第六课】接口interface
Java提供的这个interface的语法,目的就是将接口从类中剥离出来,构成独立的主体. 首先加入我们定义了这个杯子接口: interface Cup { void addWater(int w); ...
- TypeScript学习指南第二章--接口(Interface)
接口(Interface) TypeScript的核心机制之一在于它的类型检查系统(type-checker)只关注一个变量的"模型(shape)" 稍后我们去了解这个所谓的形状是 ...
- Go语言学习笔记(四)结构体struct & 接口Interface & 反射
加 Golang学习 QQ群共同学习进步成家立业工作 ^-^ 群号:96933959 结构体struct struct 用来自定义复杂数据结构,可以包含多个字段(属性),可以嵌套: go中的struc ...
- Java接口interface
Java接口interface 1.多个无关的类可以实现同一个接口. 2.一个类可以实现多个无关的接口. 3.与继承关系类似,接口与实现类之间存在多态性. 接口(interface)是抽象方法和常量值 ...
随机推荐
- [ES6] 12. Shorthand Properties in ES6
Where destructuring in ES6 allows you to easily get properties out of an object, this shorthand prop ...
- ccConfig(设置一些底层接口状态:是否支持动作叠加 设置fps更新间隔和位置 是否画边框等。。)
#ifndef __CCCONFIG_H__ #define __CCCONFIG_H__ #include "platform/CCPlatformConfig.h" /** @ ...
- 第12届北师大校赛热身赛第二场 C. 组合数
题目链接:http://www.bnuoj.com/bnuoj/contest_show.php?cid=3570#problem/43573 C. 组合数 Time Limit: 1000ms Ca ...
- Parse--Saving Images(翻译)
原文地址:https://www.parse.com/tutorials/saving-images 学习如何创建一个关于允许用户拍照和上传到parse.com的APP 源码地址:https://gi ...
- python 调试工具
https://github.com/what-studio/profiling http://blog.jobbole.com/51062/ http://blog.jobbole.com/5209 ...
- ZOJ 2588 Burning Bridges(求含重边的无向连通图的割边) - from lanshui_Yang
Burning Bridges Time Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little country ...
- 来自 Github 的图形化 Git 使用教程
转载:http://www.linuxeden.com/html/news/20120628/126451.html 这是来自 Github 上对 Git 常用操作进行简短介绍以及可视化图形操作说明的 ...
- ubutun中安装nginx
一.安装 sudo wget http://nginx.org/download/nginx-1.4.4.tar.gz sudo tar zxvf ng....cd nginx-1.4.4sudo . ...
- Python Counter() 的实现
Table of Contents 1. collections.Counter 源码实现 1.1. __init__ 1.2. update 1.3. most_common 1.3.1. item ...
- solr 相似查询-MoreLikeThis
参考文档: MoreLikeThis MoreLikeThisHandler 在solr中有两种方式实现MoreLikeThis:第一种:SearchHandler中的MoreLikeThisComp ...