Re: Beginner Tutorials for using CLASSES in PHP4
| From: | Robert Cummings | Date: | Wed, 10 Oct 2007 13:57:28 +0000 |
| Subject: | Re: Beginner Tutorials for using CLASSES in PHP4 | ||
| 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-263038@lists.php.net to get a copy of this message | ||
On Wed, 2007-10-10 at 14:44 +0100, Tony Marston wrote:
> ""Nathan Nobbe"" <quickshiftin@gmail.com> wrote in message
>
> news:7dd2dc0b0710091950i62159761le400b3839677bebd@mail.gmail.com...
> > On 10/9/07, Robert Cummings <robert@interjinn.com> wrote:
> >>
> >> On Tue, 2007-10-09 at 21:37 -0400, Nathan Nobbe wrote:
> >> >
> >> > does a lawn mower not have blades; and gas and a control panel; does it
> >> not
> >> > have
> >> > wheels? my object modeling of a lawn mower would certainly have these
> >> > things;
> >> > and most likely i would mark components of the engine as private.
> >> > and what does a lawn mower cut anyway; grass; i thought that was it.
> >> > so
> >> if
> >> > there
> >> > was no grass could there still be an algorithm to cut it?
> >> > i say grass is part of the grass-cutting algorithm.
> >>
> >> Well it helps to refine the algorithm, but let's say we use fingers
> >> instead as our measure... I'm sure we would find that we could cut grass
> >> also >:)
> >
> >
> > good point.
> > the lawn mower is still consistent of its own parts and they
> > comprise its implementation.
> >
> > -nathan
>
> Yes, but a lawnmower does not contain grass, it is used to cut grass. Whole
> grass goes in and cut grass comes out. The lawnmower does not have any grass
> in its construction, therefore grass is not part of the implementation.
It may not be part of it's construction, but it certainly is a member
variable. It's along the lines of the following:
<?php
class Lawnmower
{
var $works = true;
var $grassyMulchCrapStuckToUndersideOfLawnmower = 0;
function mow( $what )
{
if( !$this->works )
{
return false;
}
if( $what == 'grass' )
{
$this->grassyMulchCrapStuckToUndersideOfLawnmower +=
rand( 1, 100 );
if( $this->grassyMulchCrapStuckToUndersideOfLawnmower >
1000 )
{
return $this->seize();
}
}
else
if( $what == 'fingers' )
{
// >:)
}
return true;
}
function seize()
{
return ($this->works = false);
}
}
?>
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................