Can anybody explain the concept of interfaces with good example. I searched but didn't find a good answer. I'm still confused with these concepts.
I found an example for interface from Internet which is shown below. The code works without the interface with the same output. Then what is the purpose of it? Or is it not the real implementation of interfaces?. I need to move from procedural coding to object oriented programming. It would be better if anyone can explain not in more complex technical words.
<?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();
?>