DEV Community

Jogesh
Jogesh

Posted on

Laravel Design Patterns

Hello,

I am new to design patterns and would like to implement it to own project. I have the following application structure.

app
  -- Http
    -- Controllers
       ProductController.php
  -- Models
     Product
  -- Repositories
      -- Contracts
         ProductInterface.php
     ProductRepository.php

I need your help to understand with the following.
I want to make my codes extendable like what I have to do If I want to use the Cache for my queries or want to use the Redis?

ProductInterface.php

interface ProductInterface
{
    ...

    public function find($id);

    ...
}

ProductRepository.php

class ProductRepository implements ProductInterface
{
   ...

   public function find($id)
   {
      return $this->product->find($id);
   }

   ...
}

Any example is must appreciated.

Top comments (0)