note 108736 deleted from language.oop5.basic by googleguy

From: Date: Sat, 12 Jan 2013 11:05:21 +0000
Subject: note 108736 deleted from language.oop5.basic by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192984@lists.php.net to get a copy of this message
Note Submitter: Jeffrey ---- The PHYSICS OF THE SYSTEM You cannot take the PHYSICS out of any SYSTEM (or environment) -- man-made OR natural. In every system, there lies the laws of physics (the laws of nature). For example, a moving object -- in a natural environment OR in a lab -- is always subject to the same forces that exist anywhere. Even a computer program has an environment, for example: <?php ?> Even though it had a very short life, it had an ENVIRONMENT which had POTENTIAL TO DO WORK, which made it a good candidate for a useful SYSTEM. If we think about a 3-Dimensional space as an environment, it is easy to imagine putting 'things' or 'objects' in that space AND doing things to them. In the next invocation of PHP below, I am going to: 1. Create a 3-Dimensional space or ENVIRONMENT -- just by using the '<?php' tag. 2. Define the SYSTEM we want to use -- laws, rules, policies, structure, properties etc. -- with valid PHP class definitions. 3. Instantiate objects with the 'new' operator so we can poke it for a while. 4. Output some data to see if they obey the rules we wrote. 5. Here we go! <?php // 1. check, ENVIRONMENT created. class Wheel { public $cir = 3.0; // circumference in feet. public $rpm = 0.0; // rotations (spins) per minute. public function __toString() { return 'Wheel [' . 'cir=' . number_format($this->cir, 2) . ' ft, ' . 'rpm=' . $this->rpm . ']'; } } // Wheel defined... class Speedometer { public $wheel; public function __construct(Wheel $wheel) { $this->wheel = $wheel; } public function getSpeed() { $speed = 0.0; $wheel = $this->wheel; if($wheel->rpm != 0.0) { $fpm = $wheel->cir * $wheel->rpm; // feet per minute $fph = $fpm * 60; // feet per hour $speed = $fph / 5280; // MPH = $fph / feet per mile } return $speed; } public function __toString() { return 'Speedometer [' . 'speed=' . number_format($this->getSpeed(), 2) . ' MPH, ' . 'wheel=' . $this->wheel . ']'; } } // Speedometer defined. // 2. check, SYSTEM created. $wheel = new Wheel(); $speedometer = new Speedometer($wheel); // 3. check, Objects instantiated. while($wheel->rpm <= 1500) { echo $speedometer . "<br>\n"; $wheel->rpm += 100; } // 4. check, data outputted. ?> Speedometer [speed=0.00 MPH, wheel=Wheel [cir=3.00 ft, rpm=0]] Speedometer [speed=3.41 MPH, wheel=Wheel [cir=3.00 ft, rpm=100]] Speedometer [speed=6.82 MPH, wheel=Wheel [cir=3.00 ft, rpm=200]] ... etc ... ... etc ... Speedometer [speed=51.14 MPH, wheel=Wheel [cir=3.00 ft, rpm=1500]] 5. check, there it went.

« previous php.notes (#192984) next »