Last active
May 19, 2021 06:26
-
-
Save ksmylmz/d8561b7814b1f9e130c412679ae11222 to your computer and use it in GitHub Desktop.
adapter design pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
////Pusedio kodlar | |
class BusinessLayer | |
{ | |
public function ManageProduct() | |
{ | |
////Myslq Server Kullanmak istediğimizde | |
$productManager = new ProductManager( new MysqlAdapter()); | |
$productManager->getData($query,$params); | |
$productManager->insert($query,$params); | |
///MongoDB Kullanmak istediğimizde | |
$productManager = new ProductManager( new MongoAdapter()); | |
$productManager->getData($query,$params); | |
$productManager->insert($query,$params); | |
} | |
} | |
class ProductManager | |
{ | |
private IDatabase $DataAccessLayer; | |
function __construct(IDatabase $DataAccessLayer) | |
{ | |
$this->$DataAccessLayer = $DataAccessLayer; | |
} | |
} | |
interface IDatabase | |
{ | |
public function getData($query,$parameters); | |
public function insertData($query,$parameters); | |
public function updateData($query,$parameters); | |
public function deleteData($query,$parameters); | |
} | |
class MysqlAdapter implements IDatabase | |
{ | |
public function getData($query,$parameters) | |
{ | |
return DB::select($query,$parameters); | |
} | |
public function insertData($query,$parameters) | |
{ | |
return DB::insert($query,$parameters); | |
} | |
public function updateData($query,$parameters) | |
{ | |
return DB::update($query,$parameters); | |
} | |
public function deleteData($query,$parameters) | |
{ | |
return DB::delete($query,$parameters); | |
} | |
} | |
class MongoAdapter implements IDatabase | |
{ | |
public function getData($query,$parameters) | |
{ | |
return Mongo::select($query,$parameters); | |
} | |
public function insertData($query,$parameters) | |
{ | |
return Mongo::insert($query,$parameters); | |
} | |
public function updateData($query,$parameters) | |
{ | |
return Mongo::update($query,$parameters); | |
} | |
public function deleteData($query,$parameters) | |
{ | |
return Mongo::delete($query,$parameters); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment