Interface and Repository naming in PHP and Laravel Interface and Repository naming in PHP and Laravel laravel laravel

Interface and Repository naming in PHP and Laravel


The "good" way to name your interface should be UserRepository.

When implementing a class using an interface you are making a contract : this class will use a UserRepository. Not an interface but an actual repository.

Your class will depend on an implementation of the interface but don't care which implementation will be given when you will be wiring all your components.

You should name your implementations to reflect their specifities : EloquentUserRepository for a Eloquent based repository for instance.

It make no sense to have a DefaultUserRepository. None of your implementations should be better than an other and should get a special treatment.

I wrote "good" between brackets because at the end it's more a matter of convention in your team and you should do what works for you.

You can read more on this subject in this interesting blog post : http://verraes.net/2013/09/sensible-interfaces/


I am suggesting you to name interface UserRepository and implementation for instance EloquentUserRepository, MongoUserRepository et cetera. Leaving interface in interface name is nowadays unnecessary when majority IDEs are able to find proper file in a flash.