I'm working with the repository pattern and interfaces in Laravel and find the naming to be verbose: UserRepositoryInterface or EventRepositoryInterface. Are there other naming conventions in use that are less verbose? I want my code to remain readable to future programmers. In DDD some have suggested naming UserRepositoryInterface simply Users or AllUsers, more here: How to name repository and service interfaces?.
2 Answers
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/

- 416
- 3
- 8
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.

- 4,021
- 2
- 25
- 37
-
what about UserRepo and EloquentUserRepo? would that be considered 'standard' and readable? – dwenaus Jul 22 '14 at 22:48