Last active
August 29, 2015 14:08
-
-
Save felipecwb/347700f164a5903f4932 to your computer and use it in GitHub Desktop.
Liskov Substitution Principe
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 | |
// uma subclasse deve sobrescrever os métodos da classe pai, | |
// de tal maneira que não quebre a funcionalidade do ponto de vista do cliente. | |
namespace Application\Repository; | |
use Application\DataManager\DataManager; | |
class DataRepository | |
{ | |
protected $manager; | |
function __construct(DataManager $manager) { | |
$this->manager = $manager; | |
} | |
function find(array $where) | |
{ | |
$result = $this->manager->find($where); | |
return $result->getData(); | |
} | |
} | |
class LessDataRepository extends DataRepository | |
{ | |
function find(array $where, $limit = null, $offSet = 0) | |
{ | |
$result = $this->manager->find($where); | |
$result->setOffSet($offSet); | |
if ($limit) { | |
$result->setLimit($limit); | |
} | |
return $result->getData(); | |
} | |
} | |
$o = new LessDataRepository(new DataManager()); | |
$o->find(['city' => 'Curitiba'], 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment