removed delegation as it is not a pattern but merely a concept in OOP

This commit is contained in:
Dominik Liebler
2018-06-14 21:14:53 +02:00
parent b4a5598ad2
commit a494c07255
19 changed files with 1 additions and 958 deletions

View File

@@ -1,19 +0,0 @@
<?php
namespace DesignPatterns\More\Delegation;
class JuniorDeveloper
{
public function writeBadCode(): string
{
return 'Some junior developer generated code...';
}
/**
* Junior is authorized to call method on TeamLead (real delegation)
*/
public function writeReallyBadCode(TeamLead $teamLead): string
{
return $teamLead->writeReallyBadCode();
}
}

View File

@@ -1,52 +0,0 @@
`Delegation`__
==============
Purpose
-------
Demonstrate the Delegator pattern, where an object, instead of performing one
of its stated tasks, delegates that task to an associated helper object. In
this case TeamLead professes to writeCode and Usage uses this, while TeamLead
delegates writeCode to JuniorDeveloper's writeBadCode function. This inverts
the responsibility so that Usage is unknowingly executing writeBadCode.
Examples
--------
Please review JuniorDeveloper.php, TeamLead.php, and then Usage.php to see it all tied together.
UML Diagram
-----------
.. image:: uml/uml.png
:alt: Alt Delegation UML Diagram
:align: center
Code
----
You can also find this code on `GitHub`_
TeamLead.php
.. literalinclude:: TeamLead.php
:language: php
:linenos:
JuniorDeveloper.php
.. literalinclude:: JuniorDeveloper.php
:language: php
:linenos:
Test
----
Tests/DelegationTest.php
.. literalinclude:: Tests/DelegationTest.php
:language: php
:linenos:
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/More/Delegation
.. __: http://en.wikipedia.org/wiki/Delegation_pattern

View File

@@ -1,38 +0,0 @@
<?php
namespace DesignPatterns\More\Delegation;
class TeamLead
{
/**
* @var JuniorDeveloper
*/
private $junior;
/**
* @param JuniorDeveloper $junior
*/
public function __construct(JuniorDeveloper $junior)
{
$this->junior = $junior;
}
public function writeCode(): string
{
return $this->junior->writeBadCode();
}
public function writeBadCode(): string
{
//note that we are passing $this from teamLead context
return $this->junior->writeReallyBadCode($this);
}
/**
* Junior can call this method
*/
public function writeReallyBadCode(): string
{
return 'Even team lead can write bad code...';
}
}

View File

@@ -1,25 +0,0 @@
<?php
namespace DesignPatterns\More\Delegation\Tests;
use DesignPatterns\More\Delegation;
use PHPUnit\Framework\TestCase;
class DelegationTest extends TestCase
{
public function testTeamLeadCanBlameJuniorForBadCode()
{
$junior = new Delegation\JuniorDeveloper();
$teamLead = new Delegation\TeamLead($junior);
$this->assertEquals($junior->writeBadCode(), $teamLead->writeCode());
}
public function testTeamLeadCanWriteBadCode()
{
$junior = new Delegation\JuniorDeveloper();
$teamLead = new Delegation\TeamLead($junior);
$this->assertEquals($junior->writeReallyBadCode($teamLead), $teamLead->writeBadCode());
}
}

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>PHP</ID>
<OriginalElement>\DesignPatterns\More\Delegation\JuniorDeveloper</OriginalElement>
<nodes>
<node x="-8.0" y="134.0">\DesignPatterns\More\Delegation\JuniorDeveloper</node>
<node x="0.0" y="0.0">\DesignPatterns\More\Delegation\TeamLead</node>
</nodes>
<notes />
<edges />
<settings layout="Hierarchic Group" zoom="1.0" x="68.5" y="90.5" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Constants</Category>
<Category>Constructors</Category>
<Category>Methods</Category>
</Categories>
<VISIBILITY>private</VISIBILITY>
</Diagram>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -1,6 +1,5 @@
# More
* [Delegation](Delegation) [:notebook:](http://en.wikipedia.org/wiki/Delegation_pattern)
* [ServiceLocator](ServiceLocator) [:notebook:](http://en.wikipedia.org/wiki/Service_locator_pattern)
* [Repository](Repository)
* [EAV](EAV) [:notebook:](https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model)

View File

@@ -4,7 +4,6 @@ More
.. toctree::
:titlesonly:
Delegation/README
ServiceLocator/README
Repository/README
EAV/README