• interface


    http://php.net/manual/en/language.oop5.interfaces.php

    http://php.net/manual/zh/language.oop5.interfaces.php

    Object Interfaces 

    Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.
    Interfaces are defined in the same way as a class, but with the interface keyword replacing the class keyword and without any of the methods having their contents defined.
    All methods declared in an interface must be public; this is the nature of an interface.

    implements
    To implement an interface, the implements operator is used. All methods in the interface must be implemented within a class; failure to do so will result in a fatal error. Classes may implement more than one interface if desired by separating each interface with a comma.
    Note:
    Interfaces can be extended like classes using the extends operator.
    Note:
    The class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error.

    Constants
    It's possible for interfaces to have constants. Interface constants works exactly like class constants except they cannot be overridden by a class/interface that inherits them.


    对象接口

    使用接口(interface),可以指定某个类必须实现哪些方法,但不需要定义这些方法的具体内容。
    接口是通过 interface 关键字来定义的,就像定义一个标准的类一样,但其中定义所有的方法都是空的。
    接口中定义的所有方法都必须是公有,这是接口的特性。


    实现(implements)
    要实现一个接口,使用 implements 操作符。类中必须实现接口中定义的所有方法,否则会报一个致命错误。类可以实现多个接口,用逗号来分隔多个接口的名称。
    Note:
    实现多个接口时,接口中的方法不能有重名。
    Note:
    接口也可以继承,通过使用 extends 操作符。
    Note:
    类要实现接口,必须使用和接口中所定义的方法完全一致的方式。否则会导致致命错误。

    常量
    接口中也可以定义常量。接口常量和类常量的使用完全相同,但是不能被子类或子接口所覆盖。

    An interface, together with type-hinting, provides a good way to make sure that a particular object contains particular methods. See instanceof operator and type hinting.

    接口加上类型约束,提供了一种很好的方式来确保某个对象包含有某些方法。参见 instanceof 操作符和类型约束

    What Is an Interface? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts) https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

    Interface in Java - Javatpoint https://www.javatpoint.com/interface-in-java

    Java Interfaces http://tutorials.jenkov.com/java/interfaces.html

  • 相关阅读:
    超详细动画彻底掌握深度优先,广度优先遍历!
    拜托,别再问我什么是 B+ 树了
    高性能短链设计
    Gradle build 太慢,可能是你使用的姿势不对
    看完这些,你也能成技术专家
    x58平台 服务器电源配置 tdp
    系统掉盘,机械硬盘掉盘,固态掉盘
    centos7 修改ip和dns
    centos 修改hostname
    TCP三次握手和四次挥手过程
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6673746.html
Copyright © 2020-2023  润新知