Files
DesignPatternsPHP/Adapter/Adapter.php
2013-05-11 19:33:36 +02:00

42 lines
887 B
PHP

<?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
{
/**
* The Adapter need to wrap the Adaptee in the constructor
* much like Decorator does. Nothing is adapted here...
*/
public function getTables()
{
return $this->select('SHOW TABLES');
}
}
class SQLite implements DatabaseAdapter
{
public function getTables()
{
return system('sqlite --list-tables');
}
}