start a restructure

This commit is contained in:
Antonio Spinelli
2014-03-21 18:03:44 -03:00
parent b0b0d4a1a4
commit e59d70a0ac
180 changed files with 21 additions and 16 deletions

View File

@@ -0,0 +1,15 @@
<?php
namespace DesignPatterns\Delegation;
/**
* Class JuniorDeveloper
* @package DesignPatterns\Delegation
*/
class JuniorDeveloper
{
public function writeBadCode()
{
return "Some junior developer generated code...";
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace DesignPatterns\Delegation;
/**
* Class TeamLead
* @package DesignPatterns\Delegation
* The `TeamLead` class, he delegate work to `JuniorDeveloper`
*/
class TeamLead
{
/** @var JuniorDeveloper */
protected $slave;
/**
* Give junior developer into teamlead submission
* @param JuniorDeveloper $junior
*/
public function __construct(JuniorDeveloper $junior)
{
$this->slave = $junior;
}
/**
* TeamLead drink coffee, junior work
* @return mixed
*/
public function writeCode()
{
return $this->slave->writeBadCode();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace DesignPatterns\Tests\Delegation;
use DesignPatterns\Delegation;
/**
* DelegationTest tests the delegation pattern
*/
class DelegationTest extends \PHPUnit_Framework_TestCase
{
public function testHowTeamLeadWriteCode()
{
$junior = new Delegation\JuniorDeveloper();
$teamLead = new Delegation\TeamLead($junior);
$this->assertEquals($junior->writeBadCode(), $teamLead->writeCode());
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace DesignPatterns\Delegation;
// instantiate TeamLead and appoint to assistants JuniorDeveloper
$teamLead = new TeamLead(new JuniorDeveloper());
// team lead delegate write code to junior developer
echo $teamLead->writeCode();