note 126083 added to language.oop5.abstract

From: Date: Tue, 18 May 2021 11:37:19 +0000
Subject: note 126083 added to language.oop5.abstract
Groups: php.notes 
Request: Send a blank email to php-notes+get-216391@lists.php.net to get a copy of this message
<?php //Here is a good example of abstract class. Here BaseEmployee is not actual employee its just asbtract class that reduce our code and enforce child class to implement abstract method abstract class BaseEmployee { /** * employee common attributes could in asbtract class */ public $firstname, $lastname; function __construct($fn, $ln){ $this->firstname = $fn; $this->lastname = $ln; } public function getFullName() { return "$this->firstname $this->lastname"; } /** * asbtract method that a child class must have to define */ abstract protected static function task(); } class WebDeveloper extends BaseEmployee { static function task() { return ' Develop web application'; } } class HR extends BaseEmployee { static function task() { return ' Manage human resources'; } } /** * now instantiate and get data */ $webDeveloper = new WebDeveloper('shaikh','ahmed'); echo $webDeveloper->getFullName(); echo $webDeveloper->task(); ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 103.25.249.225) ---- Manual Page -- https://php.net/manual/en/language.oop5.abstract.php Edit -- https://main.php.net/note/edit/126083 Del: integrated -- https://main.php.net/note/delete/126083/integrated Del: useless -- https://main.php.net/note/delete/126083/useless Del: bad code -- https://main.php.net/note/delete/126083/bad+code Del: spam -- https://main.php.net/note/delete/126083/spam Del: non-english -- https://main.php.net/note/delete/126083/non-english Del: in docs -- https://main.php.net/note/delete/126083/in+docs Del: other reasons-- https://main.php.net/note/delete/126083 Reject -- https://main.php.net/note/reject/126083 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216391) next »