added facade composite and adapter

This commit is contained in:
Dominik Liebler
2011-08-21 19:44:19 +02:00
parent 72e6ff60f4
commit 1e15c7b6a4
3 changed files with 152 additions and 0 deletions

37
Adapter/Adapter.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
namespace DesignPatterns;
/**
* adapter pattern
*
* Purpose:
* to link two systems, that have different interfaces. An adapter defines interfaces that are equal for all linked
* systems and wrap functionality
*
* Examples:
* - different databases have the same interface to communicate although the underlying systems act differently
*
* this is a VERY basic example which won't work at all
*/
interface DatabaseAdapter
{
public function getTables();
}
class MySQL implements DatabaseAdapter
{
public function getTables()
{
return $this->select('SHOW TABLES');
}
}
class SQLite implements DatabaseAdapter
{
public function getTables()
{
return system('sqlite --list-tables');
}
}