note 75990 added to language.oop5.abstract

From: Date: Tue, 26 Jun 2007 01:25:34 +0000
Subject: note 75990 added to language.oop5.abstract
Groups: php.notes 
Request: Send a blank email to php-notes+get-127969@lists.php.net to get a copy of this message
I love examples. This example will let you see that an Interface and an Astract Class are two different entities. Just go and read the Object Interface section at : http://www.php.net/manual/en/language.oop5.interfaces.php and look at this example <?php /* * A Very simple example to understand why we should use ABSRACT CLASSES. * This abstract class contains 2 methods : 1 abstract and 1 common methods. * */ abstract class Shape { # Let's assume a shape will always have a base and a height protected $base; protected $height; #This function can be the same for both classes 'Triangle' and 'Rectangle' public function getValue($base,$height) { $this->base = $base; $this->height = $height; } # This might be different for each class of shape, because each Surface is calculated by a different formula ( St = b*h/2 and Sr = b*h) abstract public function surface(); } class Triangle extends Shape { # s = b*h/2 public function surface(){ return round((($this->base)*($this->height)/2),2); } } class Rectangle extends Shape { # s = b*h public function surface(){ return round((($this->base)*($this->height)),2); } } $r = new Rectangle(); $r->getValue(15,3); echo $r->surface() ."\n"; # echo 45 $t = new Triangle(); $t->getValue(15,3); echo $t->surface() ."\n"; # echo 22.5 ?> ---- Server IP: 69.147.83.197 Probable Submitter: 76.108.34.199 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.abstract.php Edit -- https://master.php.net/note/edit/75990 Del: integrated -- https://master.php.net/note/delete/75990/integrated Del: useless -- https://master.php.net/note/delete/75990/useless Del: bad code -- https://master.php.net/note/delete/75990/bad+code Del: spam -- https://master.php.net/note/delete/75990/spam Del: non-english -- https://master.php.net/note/delete/75990/non-english Del: in docs -- https://master.php.net/note/delete/75990/in+docs Del: other reasons-- https://master.php.net/note/delete/75990 Reject -- https://master.php.net/note/reject/75990 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127969) next »