mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-22 06:21:46 +02:00
comments
This commit is contained in:
parent
1d99a9e65a
commit
22dbd54cbb
@ -12,17 +12,19 @@ namespace DesignPatterns\Facade;
|
|||||||
*
|
*
|
||||||
* The first goal is to reduce coupling and folow the Law of Demeter.
|
* The first goal is to reduce coupling and folow the Law of Demeter.
|
||||||
*
|
*
|
||||||
* A Facade is meant to decouple a client and a sub-system with
|
* A Facade is meant to decouple a client and a sub-system by embedding
|
||||||
* many (but sometimes just one) interface, and of course to reduce complexity.
|
* many (but sometimes just one) interface, and of course to reduce complexity.
|
||||||
*
|
*
|
||||||
* 1. A facade does not forbid you the access to the sub-system
|
* 1. A facade does not forbid you the access to the sub-system
|
||||||
* 2. You can (you shoud) have multiple facades for one sub-system
|
* 2. You can (you should) have multiple facades for one sub-system
|
||||||
*
|
*
|
||||||
* That's why a good facade has no "new" in it. If there are multiple creations
|
* That's why a good facade has no "new" in it. If there are multiple creations
|
||||||
* for each method, it is not a Facade, it's a Builder or a
|
* for each method, it is not a Facade, it's a Builder or a
|
||||||
* [Abstract|Static|Simple] Factory [Method]
|
* [Abstract|Static|Simple] Factory [Method].
|
||||||
*
|
*
|
||||||
* The best facade has no new and a constructor with interface-type-hinted parameters
|
* The best facade has no new and a constructor with interface-type-hinted parameters.
|
||||||
|
* If you need creation of new instances, use Factory as argument.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class Computer
|
class Computer
|
||||||
{
|
{
|
||||||
@ -30,6 +32,10 @@ class Computer
|
|||||||
protected $opsys;
|
protected $opsys;
|
||||||
protected $bios;
|
protected $bios;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the perfect time to use a dependency injection container
|
||||||
|
* to creaate an instance of this class
|
||||||
|
*/
|
||||||
public function __construct(BiosInterface $bios, OsInterface $os)
|
public function __construct(BiosInterface $bios, OsInterface $os)
|
||||||
{
|
{
|
||||||
$this->bios = $bios;
|
$this->bios = $bios;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user