L — Liskov Substitution

  1. SSingle Responsibility
  2. OOpen/Closed
  3. LLiskov Substitution
  4. IInterface Segregation
  5. DDependency Inversion

Shape

Before

interface InventoryRepository
{
    public function save(Item $item): void;
}

class CachedInventoryRepository implements InventoryRepository
{
    public function save(Item $item): void
    {
        throw new RuntimeException('Cache repository is read-only');
    }
}

After

interface InventoryReader
{
    public function find(int $id): Item;
}

interface InventoryWriter extends InventoryReader
{
    public function save(Item $item): void;
}

class CachedInventoryRepository implements InventoryReader
{
    public function find(int $id): Item { return $this->cache->get($id); }
}
{CC}