Created
August 1, 2014 00:41
-
-
Save giovanisilveira/3261d577f4de90300743 to your computer and use it in GitHub Desktop.
This file contains 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 | |
interface DAOFactory | |
{ | |
public function createAccessDAO(); | |
public function createClientDAO(); | |
public function createAddressDAO(); | |
} | |
/** | |
* Concrete AccessDAO | |
*/ | |
class AccessDAO | |
{ | |
/** | |
* Retrieve instance of Access | |
* @param String $login | |
* @return Access | |
*/ | |
public function getAccessByLogin($login) | |
{ | |
} | |
} | |
/** | |
* Concrete ClientDAO | |
*/ | |
class ClientDAO | |
{ | |
/** | |
* Retrieve instance of Client | |
* @param int $id | |
* @return Client | |
*/ | |
public function getById($id) | |
{ | |
} | |
} | |
/** | |
* Concrete AddressDAO | |
*/ | |
class AddressDAO | |
{ | |
/** | |
* Retrieve instance of Address | |
* @param Access $access | |
* @return Address | |
*/ | |
public function getByAccess(Access $access) | |
{ | |
} | |
} | |
/** | |
* Entity Access | |
*/ | |
class Access { | |
private $id; | |
private $login; | |
private $client; | |
private $address; | |
/** | |
* DAO Objects | |
*/ | |
private $DAOFactory; | |
private $clientDAO; | |
private $addressDAO; | |
public function getters() { | |
} | |
public function setters() { | |
} | |
public function setDAOFactory(DAOFactory $DAOFactory) | |
{ | |
$this->DAOFactory = $DAOFactory; | |
} | |
private function checkDAOFactory() | |
{ | |
if (!$this->DAOFactory instanceof DAOFactory) { | |
throw RuntimeException("Set a DAOFactory."); | |
} | |
return $this->DAOFactory; | |
} | |
public function getClient() | |
{ | |
if (!$this->clientDAO instanceof ClientDAO) { | |
$this->clientDAO = $this->checkDAOFactory()->createClientDAO(); | |
} | |
return $this->clientDAO->getById($this->client);; | |
} | |
public function getAddress() | |
{ | |
if (!$this->addressDAO instanceof AddressDAO) { | |
$this->addressDAO = $this->checkDAOFactory()->createAddressDAO(); | |
} | |
return $this->addressDAO->getByAccess($this); | |
} | |
} | |
/** | |
* Entity Client | |
*/ | |
class Client { | |
} | |
/** | |
* Entity Address | |
*/ | |
class Address { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment