Interfaces in PHP: I found it in the end.... Bit messy, PHP really needs to update this inline with Java!
<?php
class Temperature {
var $value=0;
function Temperature($value) {
$this->value=$value;
}
function toCelcius() {}
function toFarenheight() {}
function getValue () {
$return $this->value;
}
}
class Celcius extends Temperature {
function Celcius($value) {
Temperature::Temperature($value);
}
function toCelcius() {}
function toFarenheight($value) {
return $this->value * 1.5;
}
}
class Farenheight extends Temperature {
function __construct($value) {
Temperature::Temperature($value);
}
function toCelcius() {
return $this->value / 1.5;
}
function toFarenheight($value) {}
}
?>
If you wanted to for implementation of the of the interface methods, you might do this;
class Temperature {
var $value=0;
function Temperature($value) {
$this->value=$value;
}
function toCelcius() {
die ( 'Method toCelcius not implemented' );
}
function toFarenheight() {
die ( 'Method toCelcius not implemented' );
}
function getValue () {
$return $this->value;
}
}