mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-27 02:00:20 +02:00
removed Interface-suffix
This commit is contained in:
@@ -5,14 +5,14 @@ namespace DesignPatterns\Behavioral\Mediator;
|
|||||||
abstract class Colleague
|
abstract class Colleague
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var MediatorInterface
|
* @var Mediator
|
||||||
*/
|
*/
|
||||||
protected $mediator;
|
protected $mediator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param MediatorInterface $mediator
|
* @param Mediator $mediator
|
||||||
*/
|
*/
|
||||||
public function setMediator(MediatorInterface $mediator)
|
public function setMediator(Mediator $mediator)
|
||||||
{
|
{
|
||||||
$this->mediator = $mediator;
|
$this->mediator = $mediator;
|
||||||
}
|
}
|
||||||
|
47
Behavioral/Mediator/ConcreteMediator.php
Normal file
47
Behavioral/Mediator/ConcreteMediator.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DesignPatterns\Behavioral\Mediator;
|
||||||
|
|
||||||
|
class ConcreteMediator implements Mediator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Subsystem\Server
|
||||||
|
*/
|
||||||
|
private $server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Subsystem\Database
|
||||||
|
*/
|
||||||
|
private $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Subsystem\Client
|
||||||
|
*/
|
||||||
|
private $client;
|
||||||
|
|
||||||
|
public function __construct(Subsystem\Database $database, Subsystem\Client $client, Subsystem\Server $server)
|
||||||
|
{
|
||||||
|
$this->database = $database;
|
||||||
|
$this->server = $server;
|
||||||
|
$this->client = $client;
|
||||||
|
|
||||||
|
$this->database->setMediator($this);
|
||||||
|
$this->server->setMediator($this);
|
||||||
|
$this->client->setMediator($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function makeRequest()
|
||||||
|
{
|
||||||
|
$this->server->process();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function queryDb(): string
|
||||||
|
{
|
||||||
|
return $this->database->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendResponse(string $content)
|
||||||
|
{
|
||||||
|
$this->client->output($content);
|
||||||
|
}
|
||||||
|
}
|
@@ -2,54 +2,11 @@
|
|||||||
|
|
||||||
namespace DesignPatterns\Behavioral\Mediator;
|
namespace DesignPatterns\Behavioral\Mediator;
|
||||||
|
|
||||||
class Mediator implements MediatorInterface
|
interface Mediator
|
||||||
{
|
{
|
||||||
/**
|
public function sendResponse(string $content);
|
||||||
* @var Subsystem\Server
|
|
||||||
*/
|
|
||||||
private $server;
|
|
||||||
|
|
||||||
/**
|
public function makeRequest();
|
||||||
* @var Subsystem\Database
|
|
||||||
*/
|
|
||||||
private $database;
|
|
||||||
|
|
||||||
/**
|
public function queryDb();
|
||||||
* @var Subsystem\Client
|
|
||||||
*/
|
|
||||||
private $client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Subsystem\Database $database
|
|
||||||
* @param Subsystem\Client $client
|
|
||||||
* @param Subsystem\Server $server
|
|
||||||
*/
|
|
||||||
public function __construct(Subsystem\Database $database, Subsystem\Client $client, Subsystem\Server $server)
|
|
||||||
{
|
|
||||||
$this->database = $database;
|
|
||||||
$this->server = $server;
|
|
||||||
$this->client = $client;
|
|
||||||
|
|
||||||
$this->database->setMediator($this);
|
|
||||||
$this->server->setMediator($this);
|
|
||||||
$this->client->setMediator($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function makeRequest()
|
|
||||||
{
|
|
||||||
$this->server->process();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function queryDb(): string
|
|
||||||
{
|
|
||||||
return $this->database->getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $content
|
|
||||||
*/
|
|
||||||
public function sendResponse($content)
|
|
||||||
{
|
|
||||||
$this->client->output($content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace DesignPatterns\Behavioral\Mediator;
|
|
||||||
|
|
||||||
interface MediatorInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* sends the response.
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
*/
|
|
||||||
public function sendResponse($content);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* makes a request
|
|
||||||
*/
|
|
||||||
public function makeRequest();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* queries the DB
|
|
||||||
*/
|
|
||||||
public function queryDb();
|
|
||||||
}
|
|
@@ -9,7 +9,7 @@ together. It is a good alternative to Observer IF you have a "central
|
|||||||
intelligence", like a controller (but not in the sense of the MVC).
|
intelligence", like a controller (but not in the sense of the MVC).
|
||||||
|
|
||||||
All components (called Colleague) are only coupled to the
|
All components (called Colleague) are only coupled to the
|
||||||
MediatorInterface and it is a good thing because in OOP, one good friend
|
Mediator interface and it is a good thing because in OOP, one good friend
|
||||||
is better than many. This is the key-feature of this pattern.
|
is better than many. This is the key-feature of this pattern.
|
||||||
|
|
||||||
UML Diagram
|
UML Diagram
|
||||||
@@ -24,18 +24,18 @@ Code
|
|||||||
|
|
||||||
You can also find this code on `GitHub`_
|
You can also find this code on `GitHub`_
|
||||||
|
|
||||||
MediatorInterface.php
|
|
||||||
|
|
||||||
.. literalinclude:: MediatorInterface.php
|
|
||||||
:language: php
|
|
||||||
:linenos:
|
|
||||||
|
|
||||||
Mediator.php
|
Mediator.php
|
||||||
|
|
||||||
.. literalinclude:: Mediator.php
|
.. literalinclude:: Mediator.php
|
||||||
:language: php
|
:language: php
|
||||||
:linenos:
|
:linenos:
|
||||||
|
|
||||||
|
ConcreteMediator.php
|
||||||
|
|
||||||
|
.. literalinclude:: ConcreteMediator.php
|
||||||
|
:language: php
|
||||||
|
:linenos:
|
||||||
|
|
||||||
Colleague.php
|
Colleague.php
|
||||||
|
|
||||||
.. literalinclude:: Colleague.php
|
.. literalinclude:: Colleague.php
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace DesignPatterns\Tests\Mediator\Tests;
|
namespace DesignPatterns\Tests\Mediator\Tests;
|
||||||
|
|
||||||
use DesignPatterns\Behavioral\Mediator\Mediator;
|
use DesignPatterns\Behavioral\Mediator\ConcreteMediator;
|
||||||
use DesignPatterns\Behavioral\Mediator\Subsystem\Client;
|
use DesignPatterns\Behavioral\Mediator\Subsystem\Client;
|
||||||
use DesignPatterns\Behavioral\Mediator\Subsystem\Database;
|
use DesignPatterns\Behavioral\Mediator\Subsystem\Database;
|
||||||
use DesignPatterns\Behavioral\Mediator\Subsystem\Server;
|
use DesignPatterns\Behavioral\Mediator\Subsystem\Server;
|
||||||
@@ -13,7 +13,7 @@ class MediatorTest extends TestCase
|
|||||||
public function testOutputHelloWorld()
|
public function testOutputHelloWorld()
|
||||||
{
|
{
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
new Mediator(new Database(), $client, new Server());
|
new ConcreteMediator(new Database(), $client, new Server());
|
||||||
|
|
||||||
$this->expectOutputString('Hello World');
|
$this->expectOutputString('Hello World');
|
||||||
$client->request();
|
$client->request();
|
||||||
|
@@ -28,7 +28,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface "
|
"All components (called Colleague) are only coupled to the Mediator interface "
|
||||||
"and it is a good thing because in OOP, one good friend is better than many. "
|
"and it is a good thing because in OOP, one good friend is better than many. "
|
||||||
"This is the key-feature of this pattern."
|
"This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@@ -33,10 +33,10 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface and it is a good thing "
|
"All components (called Colleague) are only coupled to the Mediator interface and it is a good thing "
|
||||||
"because in OOP, one good friend is better than many. This is the key-feature of this pattern."
|
"because in OOP, one good friend is better than many. This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Alle Komponenten (genannt Kollegen) sind nur abhängig vom MediatorInterface und das ist gut so, "
|
"Alle Komponenten (genannt Kollegen) sind nur abhängig vom Mediator interface und das ist gut so, "
|
||||||
"denn in der Objektorientierten Programmierung ist ein guter Freund besser als viele. Das ist das "
|
"denn in der Objektorientierten Programmierung ist ein guter Freund besser als viele. Das ist das "
|
||||||
"beste Feature bei diesem Muster."
|
"beste Feature bei diesem Muster."
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface "
|
"All components (called Colleague) are only coupled to the Mediator interface "
|
||||||
"and it is a good thing because in OOP, one good friend is better than many. "
|
"and it is a good thing because in OOP, one good friend is better than many. "
|
||||||
"This is the key-feature of this pattern."
|
"This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@@ -34,7 +34,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface "
|
"All components (called Colleague) are only coupled to the Mediator interface "
|
||||||
"and it is a good thing because in OOP, one good friend is better than many. "
|
"and it is a good thing because in OOP, one good friend is better than many. "
|
||||||
"This is the key-feature of this pattern."
|
"This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@@ -36,11 +36,11 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface "
|
"All components (called Colleague) are only coupled to the Mediator interface "
|
||||||
"and it is a good thing because in OOP, one good friend is better than many. "
|
"and it is a good thing because in OOP, one good friend is better than many. "
|
||||||
"This is the key-feature of this pattern."
|
"This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Wszystkie komponenty, nazywane Współpracownikami (ang. `Collegue`) są powiązane tylko z `MediatorInterface`. "
|
"Wszystkie komponenty, nazywane Współpracownikami (ang. `Collegue`) są powiązane tylko z `Mediator`. "
|
||||||
"Jest to kluczowy element tego wzorca."
|
"Jest to kluczowy element tego wzorca."
|
||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:16
|
#: ../../Behavioral/Mediator/README.rst:16
|
||||||
|
@@ -31,12 +31,12 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface "
|
"All components (called Colleague) are only coupled to the Mediator interface "
|
||||||
"and it is a good thing because in OOP, one good friend is better than many. "
|
"and it is a good thing because in OOP, one good friend is better than many. "
|
||||||
"This is the key-feature of this pattern."
|
"This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Todos componentes (chamados Colleague - em inglês, Colega) são acoplados "
|
"Todos componentes (chamados Colleague - em inglês, Colega) são acoplados "
|
||||||
"apenas ao MediatorInterface e é uma coisa boa porque, em POO (Programação "
|
"apenas ao Mediator e é uma coisa boa porque, em POO (Programação "
|
||||||
"Orientada a Objetos), uma boa amiga é melhor que muitas. Esta é a "
|
"Orientada a Objetos), uma boa amiga é melhor que muitas. Esta é a "
|
||||||
"característica-chave deste padrão."
|
"característica-chave deste padrão."
|
||||||
|
|
||||||
|
@@ -34,12 +34,12 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface "
|
"All components (called Colleague) are only coupled to the Mediator interface "
|
||||||
"and it is a good thing because in OOP, one good friend is better than many. "
|
"and it is a good thing because in OOP, one good friend is better than many. "
|
||||||
"This is the key-feature of this pattern."
|
"This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Все компоненты (называемые «Коллеги») объединяются в интерфейс "
|
"Все компоненты (называемые «Коллеги») объединяются в интерфейс "
|
||||||
"MediatorInterface и это хорошо, потому что в рамках ООП, «старый друг лучше "
|
"Mediator и это хорошо, потому что в рамках ООП, «старый друг лучше "
|
||||||
"новых двух»."
|
"новых двух»."
|
||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:16
|
#: ../../Behavioral/Mediator/README.rst:16
|
||||||
|
@@ -32,7 +32,7 @@ msgstr ""
|
|||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the "
|
"All components (called Colleague) are only coupled to the "
|
||||||
"MediatorInterface and it is a good thing because in OOP, one good friend "
|
"Mediator interface and it is a good thing because in OOP, one good friend "
|
||||||
"is better than many. This is the key-feature of this pattern."
|
"is better than many. This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Tüm parçalar (Görevdaş (Colleague) da denir) sadece Aracı Arayüz (Mediator Interface) ile "
|
"Tüm parçalar (Görevdaş (Colleague) da denir) sadece Aracı Arayüz (Mediator Interface) ile "
|
||||||
|
@@ -28,7 +28,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: ../../Behavioral/Mediator/README.rst:11
|
#: ../../Behavioral/Mediator/README.rst:11
|
||||||
msgid ""
|
msgid ""
|
||||||
"All components (called Colleague) are only coupled to the MediatorInterface "
|
"All components (called Colleague) are only coupled to the Mediator interface "
|
||||||
"and it is a good thing because in OOP, one good friend is better than many. "
|
"and it is a good thing because in OOP, one good friend is better than many. "
|
||||||
"This is the key-feature of this pattern."
|
"This is the key-feature of this pattern."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
Reference in New Issue
Block a user