note 85728 added to language.oop5.interfaces

From: Date: Sun, 14 Sep 2008 21:28:18 +0000
Subject: note 85728 added to language.oop5.interfaces
Groups: php.notes 
Request: Send a blank email to php-notes+get-144415@lists.php.net to get a copy of this message
In response to harryjry and mehea concerning your Weather Model. The problem is that you don't need all the things you think you need. In OOP, good class definitions get to the point rather quickly. <?php class Weather{ public $time, $temperature, $humidity; public function __construct($tm, $t, $h){ $this->time = $tm; $this->temperature = $t; $this->humidity = $h; } public function __toString(){ return "Time: $this->time, Temperature: $this->temperature&deg;, Humidity: $this->humidity%"; } } $forecasts = array( new Weather("1:00 pm", 65, 42), new Weather("2:00 pm", 66, 40), new Weather("3:00 pm", 68, 39) // add more weather reports as desired... ); echo "Forecast for Chicago, IL:<br>"; foreach($forecasts as $forecast) echo ' - ' . $forecast '<br>'; ?> Forecast for Chicago, IL: - Time: 1:00 pm, Temperature: 65°, Humidity: 42% - Time: 2:00 pm, Temperature: 66°, Humidity: 40% - Time: 3:00 pm, Temperature: 68°, Humidity: 39% Note: MySQL can store data like this already, but if you included constants, more variables, and other functions in the Weather class, then maybe, just maybe it could be of use. ---- Server IP: 69.147.83.197 Probable Submitter: 67.150.127.147 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php Edit -- https://master.php.net/note/edit/85728 Del: integrated -- https://master.php.net/note/delete/85728/integrated Del: useless -- https://master.php.net/note/delete/85728/useless Del: bad code -- https://master.php.net/note/delete/85728/bad+code Del: spam -- https://master.php.net/note/delete/85728/spam Del: non-english -- https://master.php.net/note/delete/85728/non-english Del: in docs -- https://master.php.net/note/delete/85728/in+docs Del: other reasons-- https://master.php.net/note/delete/85728 Reject -- https://master.php.net/note/reject/85728 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144415) next »