Skip to content

Instantly share code, notes, and snippets.

@felipecwb
Last active August 29, 2015 14:08
Show Gist options
  • Save felipecwb/347700f164a5903f4932 to your computer and use it in GitHub Desktop.
Save felipecwb/347700f164a5903f4932 to your computer and use it in GitHub Desktop.
Liskov Substitution Principe
<?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