Re: Re: Repetitive answers . . .
| From: | Robert Cummings | Date: | Fri, 16 Sep 2011 13:38:11 +0000 |
| Subject: | Re: Re: Repetitive answers . . . | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314899@lists.php.net to get a copy of this message | ||
On 11-09-15 09:31 PM, Joshua Stoutenburg wrote:
class baboon {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 {$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);
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.