ruk·si

PHP
Interface

Updated at 2013-04-08 13:59

This a basic example of an interface and two classes that implement it.

interface Actor {
    public function act();
}

interface Person {
    public function breath();
}

class Knight implements Actor, Person {
    public function act() {
        echo 'I am so pretty!';
    }
    public function breath() {
        echo '*gasp*';
    }
}

class Golem implements Actor {
    public function act() {
        echo 'Glonk Glink!';
    }
}

$lancelot = new Knight();
$lancelot->act();

$grugar = new Golem();
$grugar->act();