Re: Re: Repetitive answers . . .

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11-09-15 09:31 PM, Joshua Stoutenburg wrote:
class baboon
{
     $ammo = '';

     public __construct($ammo)
     {
         $this->ammo = $ammo;
     }

     public function flingAt($target)
     {
         $target->flingAlert($this->ammo);
     }
}


$me = new baboon($information);
$you = new baboon();
$me->flingAt($you);

I'm sorry, but this is unnacceptably ambiguous. Due to the poor design I don't know whether to duck or open my mouth for a treat. Let's make the program a bit more flexible and useful...

<?php

class baboon extends mammal
{
    public function fling( $something, $target )
    {
        $target->flingAlert( $something, $target );
    }

    public function openMouth()
    {
        echo "Aaaaaaaaaaaaaaaaaaah\n";
    }

    public function evade()
    {
        if( rand( 1, 100 ) <= 70 )
        {
            echo "Pheeeeeeew! That was close.\n";
        }
        else
        {
            echo "SPLAT!\n";
        }
    }

    public function flingAlert( $something, $target )
    {
        switch( $something )
        {
            case 'treat':
            {
                $this->openMouth();
                break;
            }

            default:
            {
                $this->evade();
                break;
            }
        }
    }
}

$me = new baboon();
$you = new baboon();

$me->fling( 'scooby snack', $you );
$me->fling( 'poo', $you );

?>

I love Friday :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux