-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More than one repository files? #67
Comments
Is the files here also mean a new struct/instance of repo likes The idea of the repository instance lies in the interface or the abstraction itself from the use-cases dependency. I think |
Hi @Ajilagi , thanks for answering my question.
Yes, it will have different struct, different interface (but still in domain/user.go), and different New function.
It's still the same using mysql, if user_addresses will call another 3rd party app I will create a new folder inside repository folder, ex: (repository/useraddressservice/user_address_service.go) The point I asking that is because if I combine User CRUD function and UserAddress CRUD function in one file (which is inside user_mysql_repo.go), the file will be too large because it will contains around 8 functions. But if I separate user and user_address into different file, I will have two New function that I need to call in usecase. |
Is there any reason to make a different interface ?
Really is gonna possible? The point of my answer is why do you need an abstraction (interfaces) if you ain't gonna need it YAGNI.
Nothing too small with 1 function, and nothing too large with 8 functions. It always depend on the domain/entities functionalities itself
Yaaa correct, if you think it's too big to be read in one file split into some smaller files, just files, that's the answer
It's a bad idea because it's looks like But maybe, If you want to keep the interface smaller you can try use the composition idea likes // UserRepository implementing UserAddressRepository and it's own contract
type UserRepository interface{
UserAddressRepository
// ...
}
// UserAddressRepository contains any contract of the `user_addresses`
type UserAddressRepository interface{
// ...
}
type mysqlUserRepo struct{
}
// NewUserRepository implementing UserRepository
// so you only need to call 1 New() function
func NewUserRepository() UserRepository {
return mysqlUserRepo{}
} "The best software design is simple and easy to understand. The next time you're starting a new project, instead of thinking, "How will I architect this system, what battle-tested patterns should I use and what formal methodology should I document it with?", think "How can I come up with the simplest possible design, in a way that's easy for anyone to understand" |
Will try this, looks good to fix my problem. Thank for answering my question. |
Hi @bxcodec , thank you for creating this arch.
I have a question, should I create multiple repository files to handle multiple tables?
For Example I have users and user_addresses tables, and then I create user domain to handle both user and user address. If I have separate Create, Update, Delete function between user and user address, should I create two repository files (user_mysql_repo.go and user_address_mysql_repo.go) or I just create one repository file (user_mysql_repo.go).
Thanks
The text was updated successfully, but these errors were encountered: