note 84804 added to language.oop5.interfaces
| From: | mehea at osu1 dot php dot net | Date: | Wed, 30 Jul 2008 18:55:29 +0000 |
| Subject: | note 84804 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142953@lists.php.net to get a copy of this message | ||
While a subclass may implement an interface by extending an abstract class that implements the
interface, I question whether it is good design to to do so. Here's what I would suggest while
taking the liberty of modifying the above weather/wet model:
interface water
{
public function makeItWet();
}
/**
* abstract class implements water but defines makeItWet
* in the most general way to allow child class to
* provide specificity
**/
abstract class weather implements water
{
private $cloudy;
public function makeItWet(){}
abstract public function start();
abstract public function getCloudy();
abstract public function setCloudy();
}
class rain extends weather {
private $cloudy;
public function start() {
return "Here's some weather. ";
}
public function makeItWet() {
return 'it is raining cats and dogs today.';
}
public function getCloudy() {
return $this->cloudy;
}
public function setCloudy($bln=false) {
$this->cloudy = $bln;
}
}
$a = new rain();
echo $a->start();
$a->setCloudy(true);
if ($a->getCloudy()) {
echo 'It is a cloudy day and ';
}
echo $a->makeItWet();
?>
----
Server IP: 69.147.83.197
Probable Submitter: 216.244.42.52
----
Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php
Edit -- https://master.php.net/note/edit/84804
Del: integrated -- https://master.php.net/note/delete/84804/integrated
Del: useless -- https://master.php.net/note/delete/84804/useless
Del: bad code -- https://master.php.net/note/delete/84804/bad+code
Del: spam -- https://master.php.net/note/delete/84804/spam
Del: non-english -- https://master.php.net/note/delete/84804/non-english
Del: in docs -- https://master.php.net/note/delete/84804/in+docs
Del: other reasons-- https://master.php.net/note/delete/84804
Reject -- https://master.php.net/note/reject/84804
Search -- https://master.php.net/manage/user-notes.php