Skip to content

Instantly share code, notes, and snippets.

@EnragedSuccubus
Last active January 5, 2016 03:51
Show Gist options
  • Save EnragedSuccubus/45a5956d8e45701d95b3 to your computer and use it in GitHub Desktop.
Save EnragedSuccubus/45a5956d8e45701d95b3 to your computer and use it in GitHub Desktop.
PHP Interfaces eg 02
/**
* Class CarA
*/
class CarA implements Automobile {
protected $specs;
/**
* Constructor
*
* @param object $specs The object of data defining Car A
*/
public function __construct( $specs ) {
$this->specs = $specs;
}
/**
* steering_wheel function
*
* Required by Automobile Interface
*
* Checks the car specs for what type of steering we have.
*/
public function steering_wheel() {
switch ( $this->specs->steering ) {
case 'tilt-wheel':
echo 'The original Tilt Wheel!';
break;
case 'adjust-column':
echo 'Adjustable Steering Column';
break;
default:
echo 'Just another standard steering wheel.';
}
}
/**
* wheels function
*
* Required by Automobile interface
*
* Checks the car specs for what type of wheels we have.
*/
public function wheels() {
switch ( $this->specs->wheels ) {
case 'mag':
echo 'Mag Wheels';
break;
case 'chrome':
echo 'Chrome Wheels';
break;
default:
echo 'Alloy Wheels';
break;
}
}
/**
* floor-mats function
*
* This is NOT defined by the Automobile interface
*
* Special method unique to CarA because they need floor mats :)
*/
public function floor_mats() {
echo 'This car has special floor mats!';
}
}
/**
* Class CarB
*/
class CarB implements Automobile {
protected $specs;
/**
* Constructor
*
* @param object $specs The object of data defining Car A
*/
public function __construct( $specs ) {
$this->specs = $specs;
}
/**
* steering_wheel function
*
* Required by Automobile Interface
*
* Checks the car specs for what type of steering we have.
*/
public function steering_wheel() {
switch ( $this->specs->steering ) {
case 'tilt-wheel':
echo 'The original Tilt Wheel!';
break;
case 'adjust-column':
echo 'Adjustable Steering Column';
break;
default:
echo 'Just another standard steering wheel.';
}
}
/**
* wheels function
*
* Required by Automobile interface
*
* Checks the car specs for what type of wheels we have.
*/
public function wheels() {
switch ( $this->specs->wheels ) {
case 'mag':
echo 'Mag Wheels';
break;
case 'chrome':
echo 'Chrome Wheels';
break;
default:
echo 'Alloy Wheels';
break;
}
}
/**
* hatch_back function
*
* This is NOT defined by the Automobile interface
*
* Special method unique to CarA because hatch backs rock :)
*/
public function hatch_back() {
echo 'More space for your stuff, it\'s got a hatch back!';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment