mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-25 22:09:23 +02:00
added facade composite and adapter
This commit is contained in:
37
Adapter/Adapter.php
Normal file
37
Adapter/Adapter.php
Normal 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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user