<?php
interface eat
{
function jutieat($food);
}
class human implements eat
{
function jutieat($food)
{
echo 'human eating...';
}
}
class animal implements eat
{
function jutieat($food)
{
echo 'animal eating....';
}
}
function eat($obj)
{
if($obj instanceof eat)
{
$obj->jutieat('food');
}
else
{
echo 'nothing...';
}
}
$me=new human();
$notme=new animal();
eat($me);
eat($notme);
这样,人和动物只要吃就可以了,不需要再去关注吃的过程