mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-19 05:01:15 +02:00
start a restructure
This commit is contained in:
15
More/Delegation/JuniorDeveloper.php
Normal file
15
More/Delegation/JuniorDeveloper.php
Normal 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...";
|
||||
}
|
||||
}
|
32
More/Delegation/TeamLead.php
Normal file
32
More/Delegation/TeamLead.php
Normal 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();
|
||||
}
|
||||
}
|
18
More/Delegation/Test/DelegationTest.php
Normal file
18
More/Delegation/Test/DelegationTest.php
Normal 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());
|
||||
}
|
||||
}
|
9
More/Delegation/Usage.php
Normal file
9
More/Delegation/Usage.php
Normal 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();
|
Reference in New Issue
Block a user