Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (43 sloc) 1.2 KB
<?php
interface TroopsInterface{
public function health();
public function target();
}
class HogRider implements TroopsInterface
{
public function health ()
{
return 100;
}
public function target ()
{
return "Building";
}
}
class Minion implements TroopsInterface
{
public function health ()
{
return 70;
}
public function target ()
{
return "Air and ground";
}
}
class Troops
{
private $troops;
function __construct(TroopsInterface $troops)
{
$this->troops= $troops;
}
public function details()
{
echo $this->troops->health().PHP_EOL;
echo $this->troops->target().PHP_EOL;
}
}
(new Troops(new HogRider))->details();
(new Troops(new Minion))->details();
?>
You can’t perform that action at this time.