Skip to content

Instantly share code, notes, and snippets.

@vijaycs85
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijaycs85/a4871229662af284baa9 to your computer and use it in GitHub Desktop.
Save vijaycs85/a4871229662af284baa9 to your computer and use it in GitHub Desktop.
$user = new User($stoage);
<?php
$storage = new DatabaseStorage($host, $username, $password);
$user = new User($stoage);
<?php
Class DatabaseStorage extends StorageInterface {
public function insert($bin, array $data) {
// Query to insert into bin/table.
}
}
<?php
Interface StorageInterface {
public function insert($data);
public function delete();
public function update();
}
<?php
Class User {
public function add($uid, $name) {
$storage = new DatabaseStorage();
$storage->insert('user', array($uid, $name));
}
}
<?php
Class User {
protected $stoage;
public function __construct(StorageInterface $storage) {
$this->storage = $storage;
}
public function add($uid, $name) {
$this->storag->insert('user', array($uid, $name));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment