Tom Truyen
01/29/2024, 12:34 PMinterface UserRepository
and class UserRepositoryImpl: UserRepository
or
interface IUserRepository
and class UserRepository: IUserRepository
Or are there any alternative practices?Sam
01/29/2024, 12:52 PMKlitos Kyriacou
01/29/2024, 12:53 PMclass UserRepositoryImpl: UserRepository
- the class name seems to imply there is only ever going to be one implementation. In that case, why have an interface at all? Just create a class.
class UserRepository: IUserRepository
- this smells of Hungarian Notation, which went out of fashion at the beginning of this century.
I would make the names more meaningful:
class PostgresUserRepository: UserRepository
class MockUserRepository: UserRepository
Chris Fillmore
01/29/2024, 2:03 PMImpl
is fine. Or better yet, something descriptive as mentioned aboveShawn
01/30/2024, 12:14 AMShawn
01/30/2024, 12:15 AMAgentNoun
naming scheme for interfaces, but at the end of the day, the convention is already set, and it's much easier for everyone involved to just follow the convention instead of bikeshedding. You wouldn't use JVM-style naming while writing for the .NET CLR, after all.
I would say avoid Impl
as much as possible because it sets a bad precedent. Strive to describe exactly how you're implementing the given behavior, like how Klitos describeddamian
01/30/2024, 3:07 PMRealX
, e.g. RealUserRepository
. Sometimes if there are more possibilities for the real implementation depending on context, but that one is the default, I've used DefaultUserRepository
.