Different class implements one interface : Interface « Class « PHP






Different class implements one interface


<?php

class Person {
    public $name;
    function __construct( $name ) {
        $this->name = name;
        print "Person constructed with $name\n";
    }
}

interface Command {
    function execute();
}

class FtpCommand implements Command {
    function setHost( $host ) {
        print "FtpCommand::setHost(): $host\n";
    }

    function setUser( $user ) {
        print "FtpCommand::setUser(): $user\n";
    }

    function execute() {
    }
}

class PersonCommand implements Command {
    function setPerson( Person $person ) {
        print "PersonCommand::setPerson(): {$person->name}\n";
    }
    
    function execute() {
    }
}

?>

           
       








Related examples in the same category

1.Implement an interface
2.A Sample Interface
3.Implementing Multiple Interfaces
4.Defining an interface
5.Defining and Using an Interface
6.Using Type Hinting with Interfaces