Created
May 12, 2015 15:20
-
-
Save mageekguy/f873ffaf0cdc5f69d108 to your computer and use it in GitHub Desktop.
Extends and private properties are in a boat…
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 | |
namespace | |
{ | |
class abscisse | |
{ | |
private $value; | |
function __construct($value) | |
{ | |
$this->value = $value; | |
} | |
} | |
class ordinate extends abscisse | |
{ | |
} | |
class point | |
{ | |
private | |
$x, | |
$y | |
; | |
function __construct(abscisse $x, ordinate $y) | |
{ | |
$this->x = $x; | |
$this->y = $y; | |
} | |
protected function abscisseAndOrdinateAreNeededByPoint(self $point) | |
{ | |
$point->abscisseAndOrdinateAre($this->x, $this->y); | |
return $this; | |
} | |
protected function abscisseAndOrdinateAre(abscisse $abscisse, ordinate $ordinate) | |
{ | |
return $this; | |
} | |
} | |
} | |
namespace myPoint | |
{ | |
class displayer | |
{ | |
function abscisseAndOrdinateAre(\abscisse $abscisse, \ordinate $ordinate) | |
{ | |
var_dump($abscisse, $ordinate); | |
return $this; | |
} | |
} | |
class point extends \point | |
{ | |
private | |
$displayer | |
; | |
function displayerIs(displayer $displayer) | |
{ | |
$this->displayer = $displayer; | |
parent::abscisseAndOrdinateAreNeededByPoint($this); | |
return $this; | |
} | |
protected function abscisseAndOrdinateAre(\abscisse $abscisse, \ordinate $ordinate) | |
{ | |
$this->displayer->abscisseAndOrdinateAre($abscisse, $ordinate); | |
return $this; | |
} | |
} | |
(new point(new \abscisse(2), new \ordinate(3)))->displayerIs(new displayer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment