PHP头条
热点:

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


可能大家都懂这些,作为不懂的我猜测了一下这个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.phpzy.comtrue/php/6442.htmlTechArticle领悟php接口中interface存在的意义 可能大家都懂这些,作为不懂的我猜测了一下这个interface的意义,他就是为了后面调用的时候再调用的方法中调用实现类中interface中存在的内容,好绕口...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐