[ create a new paste ] login | about

Link: http://codepad.org/vduny4f4    [ raw code | output | fork ]

arielcr - PHP, pasted on Nov 24:
<?php

interface WalkmanInterface {

    public function pressPlay();

}

class Walkman implements WalkmanInterface{
    
    public function pressPlay(){

        echo "Playing some music on the Walkman...";

    }

}

interface iPodInterface {

    public function touchPlay();

}

class iPod implements iPodInterface{

    public function touchPlay(){

        echo "Playing some music on the iPod...";

    }

}

class WalkmanAdapter implements iPodInterface {

    private $walkman;

    public function __construct(WalkmanInterface $walkman){

        $this->walkman = $walkman;

    }

    public function touchPlay(){

        $this->walkman->pressPlay();

    }

}

class Person {

    public function listen(iPodInterface $ipod){

        $ipod->touchPlay();

    }

}

$person = new Person;

$person->listen(new WalkmanAdapter(new Walkman));


Output:
1
Playing some music on the Walkman...


Create a new paste based on this one


Comments: