Answer the question
In order to leave comments, you need to log in
Should objects be created inside the Facade (pattern)?
I looked at the examples, and did not understand whether objects should be created inside the facade.
PHP examples taken from articles.
class Facade
{
public function transfer($amount)
{
$Bank = new Bank();
$Client = new Client();
$Log = new Log();
$Bank->OpenTransaction();
$Client->OpenTransaction();
$Log->logTransaction('Transaction open');
$Bank->transferMoney(-$amount);
$Log->logTransaction('Transfer money from bank');
$Client->transferMoney($amount);
$Log->logTransaction('Transfer money to client');
$Bank->CloseTransaction();
$Client->CloseTransaction();
$Log->logTransaction('Transaction close');
}
}
class Facade
{
private $os;
private $bios;
public function __construct(BiosInterface $bios, OsInterface $os)
{
$this->bios = $bios;
$this->os = $os;
}
public function turnOn()
{
$this->bios->execute();
$this->bios->waitForKeyPress();
$this->bios->launch($this->os);
}
public function turnOff()
{
$this->os->halt();
$this->bios->powerDown();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question