接口 的申明关键字interface,接口中不定义类成员!类成员的定义完全交给实现类来完成
在php中 ,这样创建接口:
<?php
interface IPillage{
function emptyBankAccount();
function burnDocuments();
}
class Executive implements IPillage{
private $totalStockOptions;
function emptyBankAccount(){
echo "Call CFO and ask to transfer funds to swiss bank account <br/>.";
}
function burnDocuments(){
echo "Torch the office suite<br/>.";
}
}
class Assistant implements IPillage{
function takeMemo(){
echo "Taking memo...<br/>";
}
function emptyBankAccount(){
echo "Go to shopping spree with office credit card<br/>.";
}
function burnDocuments(){
echo "start small fire in the trash can<br/>.";
}
}
$ple = new Executive();
$ple->emptyBankAccount();
$ple->burnDocuments();
$ple1 = new Assistant();
$ple1->emptyBankAccount();
$ple1->burnDocuments();
?>