Re: Beginner Tutorials for using CLASSES in PHP4

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

 



On 10/10/07, Tony Marston <tony@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>
> ""Nathan Nobbe"" <quickshiftin@xxxxxxxxx> wrote in message
> news:7dd2dc0b0710091950i62159761le400b3839677bebd@xxxxxxxxxxxxxxxxx
> > On 10/9/07, Robert Cummings <robert@xxxxxxxxxxxxx> 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.


yes, you are right about the grass not being part of the implementation; i
agree.
however; the mower as i pointed out has its own member variables that
comprise its
implementation; and earlier you suggested that member variables dont
constitute the
implementation of a class; which is wrong;

here is my example; note; no grass; but it has member variables which
comprise its implementation.

<?php
class Lawnmower {
    const GAS_MIN = 0;
    const GAS_MAX = 10;

    private $engineOn = false;
    private $gasLevel = 5;

    public function turnOn() {
        if($this->canRun()) {
            $this->engineOn = true;
        } else {
            echo 'you need to add gas to run the mower!';
        }
    }

    public function mowGrass() {
        echo 'the grass [or pehaps fingers] are being cut...';
    }

    public function turnOf() {
        $this->enginOn = false;
    }

    public function addGas($amountOfGas) {
        if(($amountOfGas + $this->gasLevel) > self::GAS_MAX) {
            $this->amountOfGas += $amountOfGas;
        } else {
            echo 'you will overflow the tank w/ all that gas.';
            return false;
        }
    }

    public function checkGasLevel() {
        return $this->gasLevel;
    }

    private function canRun() {
        $canRun = false;

        if($this->gasLevel > self::GAS_MIN) {
            $canRun = true;
        }

        return $canRun;
    }
}
?>

-nathan

[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