On Wed, 2007-10-10 at 13:30 -0500, Jay Blanchard wrote:
> [snip]
> so what are the benefits of the "with interfaces" solution over
> the"without
> > interfaces" solution
> [/snip]
> 
> Polymorphism.

Bleh, polymorphism isn't unique to interfaces. In fact, PHP has
polymorphism all over the place by virtue of it's loose type system. I
can pass ANY object to any function or method (that doesn't use PHP5's
restrictive type hinting stuff) and the code will "just use it" as long
as the appropriate member functions/variables exist. PHP doesn't need
inheritance or interfaces to achieve this. In fact this is far more
flexible than the restrictive nature of interfaces. Lemme illustrate:

class Finger
{
    function wiggle()
    {
        echo 'A finger wiggles ominously.';
    }
}

class Earthworm
{
    function wiggle()
    {
        echo 'An earthworm wiggles around.';
    }
}

function wiggle( $something )
{
    if( method_exists( $something, 'wiggle' ) )
    {
        $something->wiggle();
    }
    else
    {
        echo 'Nothing happens.';
    }
}

$finger = new Finger();
$jim = new Earthworm();

wiggle( $finger );
wiggle( $jim );

Look Ma, no inheritance, no interfaces, and we have polymorphism. in
fact, our wiggle function can take absolutely anything and just try to
wiggle it. Undoubtedly OOP purists are going to scream at this because
it just feels wrong, *hah*, too bad :)

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to