note 83582 added to language.oop5.abstract

From: Date: Tue, 03 Jun 2008 04:04:28 +0000
Subject: note 83582 added to language.oop5.abstract
Groups: php.notes 
Request: Send a blank email to php-notes+get-140076@lists.php.net to get a copy of this message
here is a real world example of abstract using: a (abstract) person class a student and an employee final class, which extends person class. simple theory is that both student and employee is an extension of the person class. the difference lies on which table the data is written on, and what other pre processing (ie mandatory field checking, type checking, etc.) needed before writing each of the classes. codes: <?php abstract class person { abstract protected function write_info(); public $LastName; public $FirstName; public $BirthDate; public function get_Age($today=NULL){ //age computation function } } final class employee extends person{ public $EmployeeNumber; public $DateHired; public function write_info(){ echo "Writing ". $this->LastName . "'s info to emloyee dbase table"; //ADD unique mandatory checking unique to EMPLOYEE ONLY //actual sql codes here } } final class student extends person{ public $StudentNumber; public $CourseName; public function write_info(){ echo "Writing ". $this->LastName . "'s info to student dbase table"; //ADD unique mandatory checking unique to STUDENT ONLY //actual sql codes here } } ///---------- $personA = new employee; $personB = new student; $personA->FirstName="Joe"; $personA->LastName="Sbody"; $personB->FirstName="Ben"; $personB->LastName="Dover"; $personA->write_info(); ?> OUTPUT:Writing Sbody's info to emloyee dbase table ---- Server IP: 69.147.83.197 Probable Submitter: 203.131.91.142 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.abstract.php Edit -- https://master.php.net/note/edit/83582 Del: integrated -- https://master.php.net/note/delete/83582/integrated Del: useless -- https://master.php.net/note/delete/83582/useless Del: bad code -- https://master.php.net/note/delete/83582/bad+code Del: spam -- https://master.php.net/note/delete/83582/spam Del: non-english -- https://master.php.net/note/delete/83582/non-english Del: in docs -- https://master.php.net/note/delete/83582/in+docs Del: other reasons-- https://master.php.net/note/delete/83582 Reject -- https://master.php.net/note/reject/83582 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140076) next »