任何人都可以用很好的例子来解释接口的概念。我搜索但没有找到一个好的答案。我仍然对这些概念感到困惑。
我从 Internet 上找到了一个接口示例,如下所示。该代码在没有具有相同输出的接口的情况下工作。那么它的目的是什么?或者它不是接口的真正实现?我需要从过程编码转向面向对象的编程。如果有人可以不用更复杂的技术语言来解释,那就更好了。
<?php
interface IPillage
{
public function emptyBankAccounts();
public function burnDocuments();
}
class Employee
{
public function emptyBankAccounts()
{
echo "Call employees and ask to transfer funds to Swiss bank account";
}
public function burnDocuments()
{
echo "Torch the office suite of the employee";
}
}
class Executive extends Employee implements IPillage
{
public function emptyBankAccounts()
{
echo "Call executive and ask to transfer funds to Swiss bank account";
}
public function burnDocuments()
{
echo "Torch the office suite of the executive";
}
}
$obj1=new Employee();
$obj2=new Executive();
$obj1->emptyBankAccounts();
echo '<br>';
$obj2->emptyBankAccounts();
?>