In software development, it's often important to simplify an API or to make drastic changes to the way a user interacts with the underlying system library. Whenever we do this we can write a facade to assemble parts, restructure/combine API calls, or mock out a api definition to work with our existing system.
Pattern that provides a unified interface to a set of interfaces in a subsystem.
/* Complex parts */ class CPU { public function freeze() { /* ... */ } public function jump( $position ) { /* ... */ } public function execute() { /* ... */ } } class Memory { public function load( $position, $data ) { /* ... */ } } class HardDrive { public function read( $lba, $size ) { /* ... */ } } /* Facade */ class Computer { protected $cpu = null; protected $memory = null; protected $hardDrive = null; public function __construct() { $this->cpu = new CPU(); $this->memory = new Memory(); $this->hardDrive = new HardDrive(); } public function startComputer() { $this->cpu->freeze(); $this->memory->load( BOOT_ADDRESS, $this->hardDrive->read( BOOT_SECTOR, SECTOR_SIZE ) ); $this->cpu->jump( BOOT_ADDRESS ); $this->cpu->execute(); } } /* Client */ $facade = new Computer(); $facade->startComputer();
The Facade Pattern allows us to make drastic library level changes without affecting the client level applications, it's also very useful for convenience methodology.
[http://en.wikipedia.org/wiki/Facade_pattern Wikipedia: Facade Pattern]