首頁  >  文章  >  後端開發  >  领悟php接口中interface存在的意义_PHP教程

领悟php接口中interface存在的意义_PHP教程

WBOY
WBOY原創
2016-07-21 15:03:08782瀏覽

可能大家都懂这些,作为不懂的我猜测了一下这个interface的意义,他就是为了后面调用的时候再调用的方法中调用实现类中interface中存在的内容,好绕口啊,写个例子留作以后看吧
pay.php

复制代码 代码如下:

interface Ipay
{
 function withmoney();

 //function withinternet();
}
class Dmeng implements Ipay
{

 function withmoney()
 {
  echo "花人民币买东西";
 }
 function withinternet()
 {
  return "用网银支付";
 }
}

usei.php
复制代码 代码如下:

include_once 'pay.php';
class main
{
 function run($vc)
 {
  $this->vc = $vc;
  $this->vc->withinternet();
  echo "yunxing";
 }

}
$com= new main();
$com->run(new Dmeng);

就是上面那样,我们将interface中的某个方法注释掉,发现再调用的时候,就没用了

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327878.htmlTechArticle可能大家都懂这些,作为不懂的我猜测了一下这个interface的意义,他就是为了后面调用的时候再调用的方法中调用实现类中interface中存在的...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn