For my personal taste i better like when Interface and all its concrente implementations are together in one folder, it is later easier to locate them all and see all possible implementations.
And i would name them a little bit different:
// Interface
Acme/Repositories/UserRepository
// Concrete implementations
Acme/Repositories/EloquentUserRepository
Acme/Repositories/MongoUserRepository
Acme/Repositories/SomeRemoteServiceUserRepository
But it is just me. Some say that append interfaces with word 'Interface' is betters, because you can quickly find all interfaces + just by reading file name you can know that it is an interface.
// HomeController.php
// you can only use interface, you don't need to additionally include concrete class that will be used, so you can remove fallowing:
use Acme\repositories\UserRepository as UserRepository;
// You can use 'use' like so if class name does not change
use Acme\interfaces\UserInterface;
// When to use as suffix
use Acme\interfaces\UserInterface as MyDifferentName;
// Use capitalized namespaces
use Acme\Interfaces\UserInterface;
Good start with Laravel! JMO, my suggestions would be to
A refactored UserRepository would look something like this:
namespace Acme\repositories;
use DB;
class UserRepository implements UserRepositoryInterface
{
protected $db;
protected $user;
public function __construct(DB db, UserInterface $user)
{
$this->db = $db;
$this->user = $user;
}
public function listUsers()
{
return $this->user->all();
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community