mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-03-15 11:50:10 +01:00
removed Interface-suffix
This commit is contained in:
parent
2627aab1d1
commit
ad830e0e84
@ -5,14 +5,14 @@ namespace DesignPatterns\Behavioral\Mediator;
|
||||
abstract class Colleague
|
||||
{
|
||||
/**
|
||||
* @var MediatorInterface
|
||||
* @var Mediator
|
||||
*/
|
||||
protected $mediator;
|
||||
|
||||
/**
|
||||
* @param MediatorInterface $mediator
|
||||
* @param Mediator $mediator
|
||||
*/
|
||||
public function setMediator(MediatorInterface $mediator)
|
||||
public function setMediator(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;
|
||||
|
||||
class Mediator implements MediatorInterface
|
||||
interface Mediator
|
||||
{
|
||||
/**
|
||||
* @var Subsystem\Server
|
||||
*/
|
||||
private $server;
|
||||
public function sendResponse(string $content);
|
||||
|
||||
/**
|
||||
* @var Subsystem\Database
|
||||
*/
|
||||
private $database;
|
||||
public function makeRequest();
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
public function queryDb();
|
||||
}
|
||||
|
@ -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).
|
||||
|
||||
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.
|
||||
|
||||
UML Diagram
|
||||
@ -24,18 +24,18 @@ Code
|
||||
|
||||
You can also find this code on `GitHub`_
|
||||
|
||||
MediatorInterface.php
|
||||
|
||||
.. literalinclude:: MediatorInterface.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
Mediator.php
|
||||
|
||||
.. literalinclude:: Mediator.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
ConcreteMediator.php
|
||||
|
||||
.. literalinclude:: ConcreteMediator.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
Colleague.php
|
||||
|
||||
.. literalinclude:: Colleague.php
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
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\Database;
|
||||
use DesignPatterns\Behavioral\Mediator\Subsystem\Server;
|
||||
@ -13,7 +13,7 @@ class MediatorTest extends TestCase
|
||||
public function testOutputHelloWorld()
|
||||
{
|
||||
$client = new Client();
|
||||
new Mediator(new Database(), $client, new Server());
|
||||
new ConcreteMediator(new Database(), $client, new Server());
|
||||
|
||||
$this->expectOutputString('Hello World');
|
||||
$client->request();
|
||||
|
@ -28,7 +28,7 @@ msgstr ""
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
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. "
|
||||
"This is the key-feature of this pattern."
|
||||
msgstr ""
|
||||
|
@ -33,10 +33,10 @@ msgstr ""
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
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."
|
||||
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 "
|
||||
"beste Feature bei diesem Muster."
|
||||
|
||||
|
@ -28,7 +28,7 @@ msgstr ""
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
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. "
|
||||
"This is the key-feature of this pattern."
|
||||
msgstr ""
|
||||
|
@ -34,7 +34,7 @@ msgstr ""
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
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. "
|
||||
"This is the key-feature of this pattern."
|
||||
msgstr ""
|
||||
|
@ -36,11 +36,11 @@ msgstr ""
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
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. "
|
||||
"This is the key-feature of this pattern."
|
||||
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."
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:16
|
||||
|
@ -31,12 +31,12 @@ msgstr ""
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
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. "
|
||||
"This is the key-feature of this pattern."
|
||||
msgstr ""
|
||||
"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 "
|
||||
"característica-chave deste padrão."
|
||||
|
||||
|
@ -34,12 +34,12 @@ msgstr ""
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
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. "
|
||||
"This is the key-feature of this pattern."
|
||||
msgstr ""
|
||||
"Все компоненты (называемые «Коллеги») объединяются в интерфейс "
|
||||
"MediatorInterface и это хорошо, потому что в рамках ООП, «старый друг лучше "
|
||||
"Mediator и это хорошо, потому что в рамках ООП, «старый друг лучше "
|
||||
"новых двух»."
|
||||
|
||||
#: ../../Behavioral/Mediator/README.rst:16
|
||||
|
@ -32,7 +32,7 @@ msgstr ""
|
||||
#: ../../Behavioral/Mediator/README.rst:11
|
||||
msgid ""
|
||||
"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."
|
||||
msgstr ""
|
||||
"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
|
||||
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. "
|
||||
"This is the key-feature of this pattern."
|
||||
msgstr ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user