Created
August 23, 2018 16:02
-
-
Save earth3300/9b71ed216af960200f8525eacf738a08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined( 'NDA' ) || exit('Access Denied.'); | |
/** | |
* Pattern Abstract Class Function | |
* | |
* @link http://www.primitivetype.com/articles/php_5_abstract_classes_and_methods.php | |
*/ | |
/** | |
* Abstract Class Vehicle. | |
*/ | |
abstract class Vehicle | |
{ | |
/** | |
* Public abstract function Gets the Number of Wheels | |
*/ | |
public abstract function getNumWheels(); | |
/** | |
* Public function Gets the Name | |
*/ | |
public function getName() | |
{ | |
return get_class($this); | |
} | |
} | |
/** | |
* Class Car Extends Vehicle. | |
*/ | |
class Car extends Vehicle | |
{ | |
/** | |
* Public Function Gets the Number of Wheels. | |
*/ | |
public function getNumWheels() | |
{ | |
return 4; | |
} | |
} | |
/** | |
* Class Bike Extends Vehicle. | |
*/ | |
class Bike extends Vehicle { | |
/** | |
* Public Function Gets the Number of Wheels. | |
*/ | |
public function getNumWheels() | |
{ | |
return 2; | |
} | |
} | |
/** | |
* Prints (echos) the number of wheels. | |
*/ | |
function printNumWheels(Vehicle $v) | |
{ | |
echo "A " . $v->getName() . " has " . $v->getNumWheels() . " wheels\n"; | |
} | |
$car = new Car(); | |
$bike = new Bike(); | |
printNumWheels($car); | |
printNumWheels($bike); | |
/* | |
output: | |
A Car has 4 wheels | |
A Bike has 2 wheels | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment