cs Facade

This commit is contained in:
Dominik Liebler 2013-09-11 16:28:06 +02:00
parent 454382d8fb
commit 754ea98fb2
3 changed files with 65 additions and 10 deletions

31
Facade/BiosInterface.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace DesignPatterns\Facade;
/**
* Class BiosInterface
*/
interface BiosInterface
{
/**
* execute the BIOS
*/
public function execute();
/**
* wait for halt
*/
public function waitForKeyPress();
/**
* launches the OS
*
* @param OsInterface $os
*/
public function launch(OsInterface $os);
/**
* power down BIOS
*/
public function powerDown();
}

View File

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Facade;
/**
@ -28,31 +24,45 @@ namespace DesignPatterns\Facade;
*/
class Facade
{
/**
* @var OsInterface
*/
protected $os;
protected $opsys;
/**
* @var BiosInterface
*/
protected $bios;
/**
* This is the perfect time to use a dependency injection container
* to creaate an instance of this class
*
* @param BiosInterface $bios
* @param OsInterface $os
*/
public function __construct(BiosInterface $bios, OsInterface $os)
{
$this->bios = $bios;
$this->opsys = $os;
$this->os = $os;
}
/**
* turn on the system
*/
public function turnOn()
{
$this->bios->execute();
$this->bios->waitForKeyPress();
$this->bios->launch($this->opsys);
$this->bios->launch($this->os);
}
/**
* turn off the system
*/
public function turnOff()
{
$this->opsys->halt();
$this->os->halt();
$this->bios->powerDown();
}
}

14
Facade/OsInterface.php Normal file
View File

@ -0,0 +1,14 @@
<?php
namespace DesignPatterns\Facade;
/**
* Class OsInterface
*/
interface OsInterface
{
/**
* halt the OS
*/
public function halt();
}