本文共 416 字,大约阅读时间需要 1 分钟。
1、接口的作用比较单一,它只能定义一些待实现的方法,不能有成员属性,无法封装数据,也不能自己实现方法。
interface DemoInterface{ public function test1(); public function test2();}
其他类通过 implements 来实现接口的所有方法。
2、抽象类的功能更加丰富,可以定义待实现的方法,数据封装,自己实现一些方法。
abstract class RobotRepositoryInterface{ private $name; abstract function searchForHot($hotBooks); function getThirdCoverByIssn($request){ echo 123; }}
其他类通过继承的方式来继承抽象类的数据,已实现的方法,然后去实现待实现的方法,或者重写父类的方法。
转载地址:http://sgxui.baihongyu.com/